我正在使用 Python 开发一个执行以下操作的应用程序:
- 监视特定目录并监视文件
转移到它。文件完成传输后,运行一些
文件上的外部程序。
我开发这个应用程序的主要问题是知道文件何时完成传输。据我所知,该文件将通过 SFTP 传输到特定目录。 Python 如何知道文件何时完成传输?我知道我可以使用st_size
返回对象的属性os.stat(fileName)
方法。我需要使用更多工具来实现这些目标吗?
我最终使用了看门狗的组合,并等到我可以打开文件进行写入
#If there is no error when trying to read the file, then it has completely loaded
try:
with io.FileIO(fileName, "r+") as fileObj:
'''
Deal with case where FTP client uses extensions such as ".part" and '.filepart" for part of the incomplete downloaded file.
To do this, make sure file exists before adding it to list of completedFiles.
'''
if(os.path.isfile(fileName)):
completedFiles.append(fileName)
print "File=" + fileName + " has completely loaded."
except IOError as ioe:
print str(ioe)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)