LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Wait for file copy to finish

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:

http://forums.ni.com/t5/LabVIEW/file-size-refresh-rate-windows-7/m-p/1242450/thread-id/525046/highli...

 

 

 

0 Kudos
Message 1 of 3
(4,105 Views)

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 ...].

0 Kudos
Message 2 of 3
(4,071 Views)

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. 

0 Kudos
Message 3 of 3
(3,912 Views)