Reputation: 1360
I am trying to use python to create a tail-like utility that can read from a file that is actively open and being written to in another process. It needs to work on windows so I am having to use the win32file module. I will need to open this file and seek to a previously saved location. I have found the SetFilePointer function which will do the moving but, when I get done, I need to store the position of the read pointer for a future iteration. There does not appear to be a function that will give them the position of the read pointer. The naming convention on these functions is not always intuitive so maybe I'm just missing it.
Upvotes: 3
Views: 1526
Reputation: 44394
Yes, SetFilePointer
is less than obvious. The current file position is also found using SetFilePointer
, specify a move method of FILE_CURRENT
and a distance of zero.
Upvotes: 1
Reputation: 613352
SetFilePointer returns the new file pointer, after modifying the pointer. So call it passing a zero offset from the current position to get the current position. Consult the docs for all the details: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365541.aspx
If there's any chance that you'll work with file pointers over 4GB, use SetFilePointerEx instead. It makes life much simpler.
Upvotes: 3