我嘗試:通過一堆文件 拷貝文件到新的位置和增量文件名,蟒蛇
- 環路進行一些更改
- 複製舊的文件到一個子目錄。這裏是踢球者,如果它已經存在,我不想覆蓋新目錄中的文件。 (例如,如果「Filename.mxd」已存在,則複製並重命名爲「Filename_1.mxd」。如果存在「Filename_1.mxd」,則將該文件複製爲「Filename_2.mxd」,依此類推......)
- 保存文件(但做了保存,而不是保存爲使其覆蓋現有文件)
它是這樣的:
for filename in glob.glob(os.path.join(folderPath, "*.mxd")):
fullpath = os.path.join(folderPath, filename)
mxd = arcpy.mapping.MapDocument(filename)
if os.path.isfile(fullpath):
basename, filename2 = os.path.split(fullpath)
# Make some changes to my file here
# Copy the in memory file to a new location. If the file name already exists, then rename the file with the next instance of i (e.g. filename + "_" + i)
for i in range(50):
if i > 0:
print "Test1"
if arcpy.Exists(draftloc + "\\" + filename2) or arcpy.Exists(draftloc + "\\" + shortname + "_" + str(i) + extension):
print "Test2"
pass
else:
print "Test3"
arcpy.Copy_management(filename2, draftloc + "\\" + shortname + "_" + str(i) + extension)
mxd.save()
因此,兩件事情我決定做,是隻是將文件的範圍設置得遠遠超出我預期的那樣(50)。我確信有一個更好的方法來做到這一點,只需遞增到下一個數字而不設置範圍。
第二件事,你可能會看到,腳本將所有內容都保存在範圍內。我只想在下一次沒有發生的情況下保存一次。
希望這是有道理的,
邁克
我試過這個,它保存時發生崩潰。不太確定爲什麼... – Mike 2012-04-10 15:08:16