【发布时间】:2017-04-03 06:22:00
【问题描述】:
我想移动源路径中只有“.hex”扩展名的文件。我写了如下代码;
os.makedirs(dst)
src = "C:\\source_path"
dst = "C:\\destination_path"
for filename in os.listdir():
if filename.endswith('.hex'):
shutil.move(src, dst , copy_function = copy2)
文件已创建但为空。
【问题讨论】:
-
为什么要使用
copy_function = copy2??尝试使用os.rename(src, dst)shutil.move(src, dst) -
您需要指定文件路径而不仅仅是目录名。
-
即使我写
shutil.move(src, dst),目标文件也没有变化。我只是试试copy_function = copy2 -
文件不断更新。没有固定的文件名。这就是为什么我尝试移动以 '.hex' 结尾的文件
标签: python python-3.x path move shutil