目前只测试了2级文件夹内的文件;是可以全部移动的;目标文件夹内全部是文件名,不再含有文件夹。
import shutil
import os
def move_files(source, dest):
for root, dirs, files in os.walk(source):
for file in files:
source_path = os.path.join(root, file)
destination_path = os.path.join(dest, file)
shutil.move(source_path, destination_path)
# 请填写要移动的源文件夹和目标文件夹的路径
source_folder = "/Users/mac/Desktop/测试文件夹"
destination_folder = "/Users/mac/Desktop/目标文件夹"
move_files(source_folder, destination_folder)