0

Say I am copying a large file (say 100 GB) from one location to another, and I would like to check how much of the file has been copied. If I use os.path.getsize(), what I end up getting is not the actual amount of the data that has been copied but the anticipated size (e.g., say only 30 GB has been copied, but os.path.getsize() still shows the full 100 GB. I wonder if there is a way to get the real size.

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
Alex
  • 4,030
  • 8
  • 40
  • 62
  • Please use the internationally agreed SI units. GB means gigabytes https://en.wikipedia.org/wiki/Gigabyte and Gb means gigabits https://en.wikipedia.org/wiki/Gigabit – Mark Setchell Jan 14 '22 at 22:05
  • I seriously doubt it. Some copy programs will create an empty file of the appropriate size, and then stop overwriting the file from the beginning. There's no good way to find where another program's write pointer is. – Frank Yellin Jan 14 '22 at 22:06
  • @MarkSetchell: I apologize for my (now deleted) reply. I thought I had typed GB but then realized that the GB was due to the edits you made. My bad. – Alex Jan 14 '22 at 23:04

1 Answers1

0

if you are the one copying the file in python, you can create a copy function with a progress callback, however if you were using python then os.path.getsize() would have probably given you the correct progress if it was called from another thread/process, so I am guessing this is not the case.

my guess is the program that's copying it is reserving the disk space before copying (which windows explorer does), so you cannot know how much was copied, and then it's probably better to switch to copying it with python where you will get the correct size when you call os.path.getsize() and also get a callback if you want.

Ahmed AEK
  • 8,584
  • 2
  • 7
  • 23