Getting file size during copy operation

Uranium-235

Member
Joined
May 23, 2022
Messages
5
Programming Experience
1-3
I notice using using Filesystem.Filecopy, the destination becomes pre-allocted in size (in this case, copied to external hard drive)

I am trying to get a timer to get the active file size being written, but that seems it might not be possible using filecopy. What I'm trying to do is get the file size directly. I know it's possible with a few other techniques but i'm trying to keep it simple here. Getting the source size, end size, and cross multiply to get the percentage written.

I'm start the filecopy in an async background worker. and the file monitor as a timer, which from the beginning shows the files full size (again, system probably pre-allocates it). I'll try to do some more research on the subject. Might have to do with it being an external hard drive
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,726
Location
Sydney, Australia
Programming Experience
10+
If you open a FileStream on the source file then its Length property is the size of the file. I've never done it but I believe that you can open a FileStream on the destination file and call SetLength to create an "empty" file of the desired size. You can then Read from the source and Write to the destination in a loop using a Byte array of known size and calculate the progress accordingly.
 
Top Bottom