【发布时间】:2019-01-02 18:59:00
【问题描述】:
之前已经给出了一些类似的解决方案,但似乎没有一个适合我。
代码:
def watch_dir(self, prefix, dest):
before = dict([(f, None) for f in os.listdir(self.data_dir)])
while 1:
time.sleep(5)
after = dict([(f, None) for f in os.listdir(self.data_dir)])
new_files = [f for f in after if not f in before and f.startswith(prefix)]
before = new_files
for f in new_files:
os.system('mv {f} {dest}'.format(f=f, dest=dest))
当我打印 new_files 我得到 -> ('new_files = ', ['sample.tsv'])
但是mv 命令给出了这个错误:
mv: cannot stat 'sample.tsv': No such file or directory
有人可以帮我理解这里可能出了什么问题吗?!
谢谢!
【问题讨论】:
-
错误提示找不到文件
sample.tsv。尝试提供文件的绝对路径,这应该可以解决它。此外,还有更好的方法在 python 中移动文件。看看:stackoverflow.com/questions/8858008/…
标签: python mv python-watchdog