之前已经给出了一些类似的解决方案,但似乎没有一个对我有用。
代码:
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
有人可以帮我理解这里可能出了什么问题吗?!
谢谢!