import os
import shutil
# 定义源文件夹和目标文件夹路径
source_folder = '/path/to/source/folder' # 源文件夹路径
target_folder = '/path/to/target/folder' # 目标文件夹路径
# 获取源文件夹中的文件列表
source_files = os.listdir(source_folder)
# 遍历源文件夹中的文件
for file in source_files:
source_file_path = os.path.join(source_folder, file)
# 检查文件是否存在于目标文件夹中
if os.path.exists(os.path.join(target_folder, file)):
target_file_path = os.path.join(target_folder, file)
# 移动文件到新的文件夹
shutil.move(source_file_path, target_file_path)
print(f"Moved file: {file}")
import os
import shutil
# 定义源文件夹和目标文件夹路径
source_folder = '/media/wagnchogn/data_disk/artifact/revise_cla_normal_artifact/test_a2n_sel' # 源文件夹路径
target_folder = '/media/wagnchogn/data_disk/artifact/revise_cla_normal_artifact/test_artifact_sel' # 目标文件夹路径
comparsion_folder = '/media/wagnchogn/data_disk/artifact/revise_cla_normal_artifact/dataset_test (copy)' # 较文件夹路径
# 获取源文件夹中的文件列表
source_files = os.listdir(source_folder)
# 遍历源文件夹中的文件
for file in source_files:
source_file_path = os.path.join(source_folder, file)
# 检查文件是否存在于较文件夹中
if os.path.exists(os.path.join(comparsion_folder, file)):
target_file_path = os.path.join(target_folder, file)
# 移动文件到新的文件夹
shutil.move(source_file_path, target_file_path)
print(f"Moved file: {file}")