[英]Python - move files from one folder to another
在下面尋找我的代碼的擴展,所以當不滿足條件時,文件將被移動到“ERROR”文件夾。 誰能幫忙? 謝謝:-)
source = '/Users/XY/Desktop/OUT'
destination = '/Users/XY/Desktop/IN'
allfiles = glob.glob(os.path.join(source, '*S*'), recursive=True)
print("Files to move", allfiles)
for file_path in allfiles:
dst_path = os.path.join(destination, os.path.basename(file_path))
shutil.move(file_path, dst_path)
print(f"Moved {file_path} -> {dst_path}")
我試圖在谷歌上搜索但沒有運氣。
for file_path in allfiles:
if some_condition:
dst_path = os.path.join(destination, os.path.basename(file_path))
else:
dst_path = os.path.join(error_folder, os.path.basename(file_path))
shutil.move(file_path, dst_path)
print(f"Moved {file_path} -> {dst_path}")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.