os.path.getsize() on Windows
half.italian at gmail.com
Thu Mar 20 18:45:03 CET 2008
On Mar 20, 6:42 am, Duncan Booth <duncan.bo... at invalid.invalid> wrote:
> Steven D'Aprano <st... at REMOVE-THIS-cybersource.com.au> wrote:
> > On Wed, 19 Mar 2008 12:34:34 +0000, Duncan Booth wrote:
> >> By default Python on Windows allows you to open a file for reading
> >> unless you specify a sharing mode which prevents it:
> > But the OP is talking about another process having opened the file for
> > WRITING, not reading. It's that other process that has exclusive access,
> > and the OP was trying to determine when it was safe to attempt opening
> > the file according to whether or not it was still growing.
> No, unless the other process has specified that it wants exclusive access
> there is nothing stopping his process also opening the file. That's why he
> has to specify when he opens it that he wants exclusive access: then it
> doesn't matter what the other process does, he won't be able to open it
> until the other process has closed the file.
> This all of course assumes that the other process writes the file in one
> single atomic chunk. If it were to create it and then separately open and
> write to it then all bets are off.
Thanks for your input.
After trying again this morning, the file is opened for reading. I
must have had some wonky permissions on that file, so the error method
won't work. Trying to use the md5 technique won't work here either.
It takes quite awhile to run one md5, let alone two on a growing
file. These files can be 20-50GB.
The overall idea is to be able to tell if a file has finished being
placed in a directory without any control over what is putting it
there. If I'm in control of the process, I know I can put it in a
temp area, etc. I use the method I mention in my original post
regularly without knowing how the file gets there, and was surprised
to see it didn't work on Windows.
In this case, there will be so few people touching the system, that I
think I can get away with having the copy be done from Unix, but it
would be nice to have a general way of knowing this on Windows.
More information about the Python-list