You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.4 KiB
54 lines
1.4 KiB
from pathlib import Path |
|
import os |
|
import shutil |
|
# 指定要遍历的文件夹路径 |
|
folder_path = Path('G://obj_fix/print') |
|
|
|
# 定义函数来递归遍历文件夹下的所有文件 |
|
def list_files(directory): |
|
for root, dirs, files in os.walk(directory): |
|
for file in files: |
|
yield os.path.join(root, file) |
|
|
|
# 指定要遍历的文件夹路径 |
|
# folder_path = folder_path |
|
|
|
# 使用list_files函数来列出文件夹下的所有文件 |
|
nums = 0 |
|
for file_path in list_files(folder_path): |
|
|
|
if "around" in file_path: |
|
continue |
|
|
|
|
|
if "_new.obj" not in file_path: |
|
continue |
|
|
|
|
|
|
|
|
|
#提取pid |
|
arrTemp = file_path.split('\\') |
|
pid = arrTemp[len(arrTemp)-2] |
|
|
|
#判段是否存在 {pid}.obj 文件,存在的话就进行重命名 |
|
initObjPath = f'G://obj_fix/print/{pid}/{pid}.obj' |
|
if not os.path.exists(initObjPath): |
|
continue |
|
|
|
#存在的话就重命名文件 |
|
old_file_path = f'G://obj_fix/print/{pid}/{pid}_old.obj' |
|
os.rename(initObjPath, old_file_path) |
|
|
|
|
|
newObjfilePath = f'G://obj_fix/print/{pid}/{pid}_new.obj' |
|
os.rename(newObjfilePath, initObjPath) |
|
|
|
# # 将 new.obj 文件复制到指定的文件夹下 G:\obj_fix\print\{pid}\ |
|
|
|
# source_obj = file_path |
|
# target_obj = f'G://obj_fix/print/{pid}/{pid}_new.obj' |
|
# print(f"当前正在处理{pid}") |
|
# shutil.copy(source_obj, target_obj) |
|
nums += 1 |
|
print(pid,file_path,nums)
|
|
|