需要一种方法来确定文件是否被写入 [英] Need a way to determine if a file is done being written to
问题描述
理想情况下
- 可在Linux或Windows上运行 - 这意味着解决方案与操作系统无关。
- 适用于任何类型的文件。
足够好:
- 只适用于Windows,但可以通过一些库或任何可以通过Python访问的方式来完成。
- PDF文件。
当前最好的想法是定期打开窗口框上的某个进程的问题文件,并查看最后一个字节检查PDF结束标记,并考虑到eol的差异,因为这个文件可能已经在Linux或Windows上创建。
最终解决了我们的情况。事实证明,把文件写出来的过程让他们完全打开,所以我们所要做的只是尝试打开它们进行读取访问 - 当被拒绝时,它们就被使用了。
The situation I'm in is this - there's a process that's writing to a file, sometimes the file is rather large say 400 - 500MB. I need to know when it's done writing. How can I determine this? If I look in the directory I'll see it there but it might not be done being written. Plus this needs to be done remotely - as in on the same internal LAN but not on the same computer and typically the process that wants to know when the file writing is done is running on a Linux box with a the process that's writing the file and the file itself on a windows box. No samba isn't an option. xmlrpc communication to a service on that windows box is an option as well as using snmp to check if that's viable.
Ideally
- Works on either Linux or Windows - meaning the solution is OS independent.
- Works for any type of file.
Good enough:
- Works just on windows but can be done through some library or whatever that can be accessed with Python.
- Works only for PDF files.
Current best idea is to periodically open the file in question from some process on the windows box and look at the last bytes checking for the PDF end tag and accounting for the eol differences because the file may have been created on Linux or Windows.
I ended up resolving it for our situation. As it turns out the process that was writing the files out had them opened exclusively so all we had to do was try opening them for read access - when denied they were in use.
这篇关于需要一种方法来确定文件是否被写入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!