02-11-2012 10:18 PM
How can I wait for a file copy to complete before allowing my program to proceed? I'm using the copy function in 'Advanced File VIs and Functions' to copy a directory with a number of files. This function returns before the file copy is complete, yet apparently the OS (Windows 7) has said it is finished, but has, in fact buffered some of the data and continues to write files for a few seconds. I am commanding several instances of my application to copy their log files to a data repository and need to serialize those copy actions.
I tried comparing the sizes of the source and destination directories, but am facing this bug:
02-12-2012 04:34 PM
This idea is a bit of a kludge, but it takes advantage of "Windows Giveth, and Windows Taketh Away". What if you did the following:
1) Write all of your files to the repository folder.
2) Write a "dummy" file (you'd want to be sure to use a "safe" name, perhaps "ThisIsADummyFile.bad")
3) Delete the dummy file.
Presumably your dummy file will be written after all your other files are written (though I suppose Windows could still buffer things somewhat). The Dummy file gets written in a separate write, so it doesn't even start to write until all the other writes finish (again, Windows still might play games here ...). Finally, you certainly cannot delete a file until Windows sees that it is present!
And if all else fails, put a 5 second delay in the code following the last write. [That's really an ugly suggestion -- it has nothing to do with the problem of file-writing, but sometimes if nothing "reasonable" works, you have to try unreasonable things ...].
02-04-2013 12:42 PM
I realize this is an old post but came upon it when I had a similar problem.
In my case, the source directory contained a link (shortcut) to a non-existent file. The copy bailed at that point. Rather than just copy the dead shortcut, it tried to copy the non-existent file. I deleted the dead links and the copy ran fine.