LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Copy File Function Does not Copy Entire File

Hi all,

 

I have a VI where I essentially copy 7-8 multi GB files (~5GB) from one location to another on my hard drive. However, I've noticed that sometimes the file will not fully transfer. Sometimes one or two files are completely empty, sometimes they only get a partial copy the data. My guess is that the copy command does not finish copying before moving on to the next file and they end up colliding. But, I don't know how to stop the behaviour as I would prefer to get it right on the first try and not have to query the data size and then re-execute the copy until it has finished copying all of the files (or try and figure out how long to wait since the files size may change based on say measurement time). Since the code is kind of short, the psuedo code equivalent of my statement is

 

for file in files

     1. copy file from path 1 to path 2

     2. wait 10ms

end

 

where 1. and 2. indicate sequence of events.

 

Thanks for any help that you can give.

0 Kudos
Message 1 of 8
(2,560 Views)

It would help to see some code and more details (e.g. OS, amount of RAM, write cache policy, etc.)

0 Kudos
Message 2 of 8
(2,533 Views)

@ControlFreq wrote:

But, I don't know how to stop the behaviour as I would prefer to get it right on the first try and not have to query the data size and then re-execute the copy until it has finished copying all of the files (or try and figure out how long to wait since the files size may change based on say measurement time).


You wouldn't need to reexecute the copy, just the checking of the file size until it was correct.  Of course, this is assuming the file size is not set by the copy before the data starts to be written.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 8
(2,487 Views)

@crossrulz wrote:

@ControlFreq wrote:

But, I don't know how to stop the behaviour as I would prefer to get it right on the first try and not have to query the data size and then re-execute the copy until it has finished copying all of the files (or try and figure out how long to wait since the files size may change based on say measurement time).


You wouldn't need to reexecute the copy, just the checking of the file size until it was correct.  Of course, this is assuming the file size is not set by the copy before the data starts to be written.


I'd (also) check the permissions (Get Permissions), to see if it changes.

0 Kudos
Message 4 of 8
(2,483 Views)

We also need to know how you are checking the file size. If this is windows, the explorer window might not correctly update until you refresh the page, for example.

 

I really doubt that LabVIEW is doing anything special. Most likely it just hands it over to a windows function and returns, while the actual copying can take a very long time for such large files, especially since they probably exceed the disk cache size. What kind of drives are these (source and destination, HD, SSD, USB stick (or fake USB stick/ SD card that pretends to be larger than it really is!), network, etc.).

 

How long does such a file copy take when you do it manually?

 

Did you check the drives for errors?

 

Are these disk location monitored by other software (OneDrive, Google Drive, etc.)

 

0 Kudos
Message 5 of 8
(2,450 Views)

Forgot to speculate about Virus tools getting in the way as well.

---------------------------------------------
Former Certified LabVIEW Developer (CLD)
0 Kudos
Message 6 of 8
(2,425 Views)

@ControlFreq wrote:

Hi all,

 

I have a VI where I essentially copy 7-8 multi GB files (~5GB) from one location to another on my hard drive. However, I've noticed that sometimes the file will not fully transfer. Sometimes one or two files are completely empty, sometimes they only get a partial copy the data. My guess is that the copy command does not finish copying before moving on to the next file and they end up colliding. But, I don't know how to stop the behaviour as I would prefer to get it right on the first try and not have to query the data size and then re-execute the copy until it has finished copying all of the files (or try and figure out how long to wait since the files size may change based on say measurement time). Since the code is kind of short, the psuedo code equivalent of my statement is

 

for file in files

     1. copy file from path 1 to path 2

     2. wait 10ms

end

 

where 1. and 2. indicate sequence of events.

 

Thanks for any help that you can give.


What does "essentially copy" mean?  It obviously doesn't mean "just copy".

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 7 of 8
(2,409 Views)

If this remains unsolved, you could do the copy "manually". In a for loop, read a few (e.g. 4096) bytes from source, write them to destination file. After you're done, make sure you flush the destination file.

 

This would be a last resort, it's definitely not desirable. It's more complex, uses more memory and CPU, but it will be more deterministic.

 

Another option is to try how a .NET copy works. It might act the same, or you might have options. Simply copying a file is probably just one static method. There might be events that are send when the copy is done.

 

dotNET File Copy.png

Message 8 of 8
(2,378 Views)