27 lines
967 B
Python
27 lines
967 B
Python
import os
|
|
import shutil
|
|
|
|
scripts_root = 'Scripts'
|
|
scripts_new_root = 'Scripts-new'
|
|
|
|
# 遍历 Scripts-new 下所有 .cs 文件,记录为 {文件名: 文件完整路径}
|
|
new_files_map = {}
|
|
for dirpath, _, filenames in os.walk(scripts_new_root):
|
|
for filename in filenames:
|
|
if filename.endswith('.cs'):
|
|
new_files_map[filename] = os.path.join(dirpath, filename)
|
|
|
|
# 遍历 Scripts 下所有 .cs 文件
|
|
for dirpath, _, filenames in os.walk(scripts_root):
|
|
for filename in filenames:
|
|
if filename.endswith('.cs') and filename in new_files_map:
|
|
target_path = os.path.join(dirpath, filename)
|
|
source_path = new_files_map[filename]
|
|
print(f'Moving: {source_path} -> {target_path}')
|
|
|
|
# 确保目标文件夹存在
|
|
os.makedirs(os.path.dirname(target_path), exist_ok=True)
|
|
|
|
# 覆盖复制(移动)
|
|
shutil.move(source_path, target_path)
|