软件雏形
This commit is contained in:
108
demo/copy_rou.py
Normal file
108
demo/copy_rou.py
Normal file
@@ -0,0 +1,108 @@
|
||||
import os
|
||||
import shutil
|
||||
|
||||
SOURCE_PATHS = [
|
||||
r"Z:\Routing\A1-ROUTING\NEW-ROUTING",
|
||||
r"Z:\Routing\A2-ROUTING\NEW-ROUTING"
|
||||
]
|
||||
DEST_PATH = r"D:\ARPTWork\rou"
|
||||
|
||||
def match_folder_name(folder_name, num_part, version_part):
|
||||
"""匹配逻辑:从第四个字符开始匹配数字编号"""
|
||||
folder_name_lower = folder_name.lower()
|
||||
num_length = len(num_part)
|
||||
|
||||
if len(folder_name_lower) < 3 + num_length:
|
||||
return False
|
||||
|
||||
num_in_name = folder_name_lower[4 : 4+num_length]
|
||||
if num_in_name != num_part.lower():
|
||||
return False
|
||||
|
||||
version_in_name = folder_name_lower[4+num_length:]
|
||||
return version_in_name.startswith(version_part.lower())
|
||||
|
||||
def copy_rou_files(source_folder, number):
|
||||
"""复制所有.rou系列文件"""
|
||||
os.makedirs(DEST_PATH, exist_ok=True)
|
||||
copied_files = []
|
||||
ed_folders_found = 0
|
||||
|
||||
for item in os.listdir(source_folder):
|
||||
item_path = os.path.join(source_folder, item)
|
||||
|
||||
if os.path.isdir(item_path) and (item.lower().startswith('ed') or item.lower().startswith('rou')):
|
||||
ed_folders_found += 1
|
||||
print(f"正在处理ED文件夹: {item}")
|
||||
|
||||
for root, _, files in os.walk(item_path):
|
||||
for file in files:
|
||||
if file.lower().endswith(('.rou', '.rou1', '.rou2', '.rou3')):
|
||||
src_file = os.path.join(root, file)
|
||||
base_name = f"{number}_{item}_{file}"
|
||||
dest_file = os.path.join(DEST_PATH, base_name)
|
||||
|
||||
shutil.copy2(src_file, dest_file)
|
||||
copied_files.append(base_name)
|
||||
|
||||
if ed_folders_found == 0:
|
||||
print("警告: 未找到任何以ED开头的文件夹")
|
||||
elif not copied_files:
|
||||
print("警告: 在ED文件夹中未找到任何.rou系列文件")
|
||||
else:
|
||||
print(f"成功从 {ed_folders_found} 个ED文件夹复制 {len(copied_files)} 个文件:")
|
||||
|
||||
def process_codes(code_list):
|
||||
"""处理多个代码"""
|
||||
for code in code_list:
|
||||
code = code.strip()
|
||||
if not code:
|
||||
continue
|
||||
|
||||
print(f"\n处理编号: {code}")
|
||||
num_part = code[:5]
|
||||
version_part = code[len(num_part):]
|
||||
|
||||
found = False
|
||||
for source_root in SOURCE_PATHS:
|
||||
num_folder = os.path.join(source_root, num_part)
|
||||
if not os.path.exists(num_folder):
|
||||
continue
|
||||
|
||||
for folder in os.listdir(num_folder):
|
||||
if match_folder_name(folder, num_part, version_part):
|
||||
full_path = os.path.join(num_folder, folder)
|
||||
print(f"找到匹配文件夹: {full_path}")
|
||||
copy_rou_files(full_path, num_part)
|
||||
found = True
|
||||
|
||||
if not found:
|
||||
print("未找到匹配的文件夹")
|
||||
|
||||
def main():
|
||||
print("=== 文件复制工具 ===")
|
||||
print(f"搜索路径: {SOURCE_PATHS}")
|
||||
print(f"目标路径: {DEST_PATH}")
|
||||
print("输入说明:")
|
||||
print("1. 直接输入单个编号,如: 27362a")
|
||||
print("2. 输入多行编号(每行一个),最后输入end结束")
|
||||
print("3. 输入exit退出程序")
|
||||
|
||||
while True:
|
||||
print("\n请输入编号(支持多行输入):")
|
||||
user_inputs = []
|
||||
|
||||
while True:
|
||||
line = input().strip()
|
||||
if line.lower() == 'end':
|
||||
break
|
||||
if line.lower() == 'exit':
|
||||
return
|
||||
if line:
|
||||
user_inputs.append(line)
|
||||
|
||||
if user_inputs:
|
||||
process_codes(user_inputs)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user