Problem with Copying files and checking exists or not?
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.
Re: Problem with Copying files and checking exists or not?
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,
_
Re: Problem with Copying files and checking exists or not?
No I ve no control. Because the copy process starts by OS copy operation.
Quote:
Originally Posted by
anda_skoa
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,
_
Re: Problem with Copying files and checking exists or not?
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?
Re: Problem with Copying files and checking exists or not?
It also fails. loading non zero size image file gives unexpected result.
Quote:
Originally Posted by
d_stranz
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?
Re: Problem with Copying files and checking exists or not?
Quote:
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"?
Re: Problem with Copying files and checking exists or not?
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.
Quote:
Originally Posted by
d_stranz
I don't know what this means. How does it fail? What is the "unexpected result"?
Re: Problem with Copying files and checking exists or not?
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,
_