Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top