0
我想在源路径中仅移动“.hex”扩展名的文件。我写下如下的代码;在Python 3中仅移动“.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)
该文件已创建但为空。
的可能的复制[使用python的水珠从目录列表文件(http://stackoverflow.com/questions/22625616/listing-files-from-a-directory-using-glob-python) –
为什么使用'copy_function = copy2'? 尝试使用 'os.rename(src,dst)' 'shutil.move(src,dst)' – Surajano
您需要指定文件路径而不仅仅是dir名称。 – bernie