这将从新路径中检查文件,并将其附加到旧文件中的空白文件中。
大多数代码已经准备就绪,只是缺少的连接:
示例新路径具有以下结构:
r"C:\Users\user\Desktop\mainfolder\PST_TO_APPEND\1211\file"
和旧的:
r"C:\Users\user\Desktop\mainfolder\PST_PROTYPO\1211\file"
如何使所有文件都基于其子文件夹中的代码进行配对?
这是我的代码,可以正常工作,但不能一次处理许多文件。
仅需连接上面的所有连接即可。
import os
... import shutil
...
... old_path = r"C:\Users\user\Desktop\mainfolder\PST_PROTYPO"
... new_path = r"C:\Users\user\Desktop\mainfolder\PST_TO_APPEND"
... #This will find the matching shape files and pass them to arcpy.Append_management():
... #part2
...
... import os
... import arcpy
...
... for dir_path, dir_names, file_names in arcpy.da.Walk(workspace=new_path, datatype="FeatureClass"):
... for filename in file_names:
... new_file_path = os.path.join(dir_path, filename)
... folder = os.path.basename(os.path.dirname(new_file_path))
... old_file_path = os.path.join(old_path, folder, filename)
... if os.path.exists(old_file_path):
... arcpy.Append_management([new_file_path], old_file_path, "NO_TEST") # appends new to old shp <------if wrong swap the new with the old file path
...