os.path.getsize() on Windows
duncan.booth at invalid.invalid
Tue Mar 18 22:27:50 CET 2008
Sean DiZazzo <half.italian at gmail.com> wrote:
> On windows, this returns the size of the file as it _will be_, not the
> size that it currently is. Is this a feature? What is the proper way
> to get the current size of the file? I noticed
> win32File.GetFileSize() Does that behave the way I expect?
> PS. I also tried os.stat()
I think all of those will return the current size of the file, but that may
be the same as the final size: just because the data hasn't been copied
doesn't mean the file space hasn't been allocated. You don't say how you
are copying the file, but I seem to remember that Windows copy command pre-
allocates the file at its final size (so as to reduce fragmentation) and
then just copies the data after that.
If you need to make sure you don't access a file until the copy has
finished then get hwatever is doing the copy to copy it to a temporary
filename in the same folder and rename it when complete. Then you just have
to check for existence of the target file.
More information about the Python-list