PDA

View Full Version : Problem with Copying files and checking exists or not?



blue_sky
3rd February 2014, 05:45
I am copying a bunch of files to a folder and checking , what are the new files copied( by QFileSystemWatcher ).
I am performing some task with newly copied files.
But sometimes it fails, bcoz during copy although QFile(fileName).exists() returns true, but physically file not present.

SO what should I do to overcome his situation particularly during copy.
Thanks in advance.

anda_skoa
3rd February 2014, 11:06
Copying a file is not an instant operation, so the file can appear in the directory before it is fully copied.

Do you have control over the program doing the copying?

Cheers,
_

blue_sky
3rd February 2014, 16:22
No I ve no control. Because the copy process starts by OS copy operation.
Copying a file is not an instant operation, so the file can appear in the directory before it is fully copied.

Do you have control over the program doing the copying?

Cheers,
_

d_stranz
3rd February 2014, 17:45
So what does QFileInfo return when you ask for the file size? Zero? Non-zero? If it returns zero at first, then the actual file size only after the copy operation is complete, then you could start a QTimer when the files first appears (QFileSystemWatcher::directoryChanged()) and check every second or so to look for a non-zero size.

What happens if in your QFileSystemWatcher::directoryChanged() slot you add a connection to the fileChanged() slot? Does that get called when the file copy is finished?

blue_sky
4th February 2014, 17:05
It also fails. loading non zero size image file gives unexpected result.
So what does QFileInfo return when you ask for the file size? Zero? Non-zero? If it returns zero at first, then the actual file size only after the copy operation is complete, then you could start a QTimer when the files first appears (QFileSystemWatcher::directoryChanged()) and check every second or so to look for a non-zero size.

What happens if in your QFileSystemWatcher::directoryChanged() slot you add a connection to the fileChanged() slot? Does that get called when the file copy is finished?

d_stranz
4th February 2014, 17:24
It also fails. loading non zero size image file gives unexpected result.

I don't know what this means. How does it fail? What is the "unexpected result"?

blue_sky
6th February 2014, 05:14
The size is non zero, but when loading image file with QImage, it gives me a data of partial image.Anyway to solve this.Thank you.

I don't know what this means. How does it fail? What is the "unexpected result"?

anda_skoa
6th February 2014, 08:47
If it fails because of unfinished copy, you will have to try again later.

Alternatively you can try to let the file system watcher only start/restart a timer and read the file when the timer runs out.
That of course depends on whether the file system watcher will signal file changes during the copy.

There is no ideal solution because you can't fix the program that is doing the copying.

Cheers,
_