|
楼主 |
发表于 2023-3-6 15:39
|
显示全部楼层
你好,我想问一下粘贴进去出现错误。
import arcpy
... import os
...
... # 定义替换函数
... def replace_text(mxd_path, old_text, new_text):
... mxd = arcpy.mapping.MapDocument(mxd_path)
... for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"):
... if elm.text == old_text:
... elm.text = new_text
... mxd.save()
... del mxd
...
... # 定义目录路径和要替换的文本
... dir_path = r"g:\ MXD_files"
... old_text = "2022年10月"
... new_text = "2023年1月"
...
... # 循环遍历目录下的所有mxd文件并替换文本
... for filename in os.listdir(dir_path):
... if filename.endswith(".mxd"):
... mxd_path = os.path.join(dir_path, filename)
... replace_text(mxd_path, old_text, new_text)
...
... print("文本替换完成!")
...
Runtime error
Traceback (most recent call last):
File "<string>", line 19, in <module>
WindowsError: [Error 3] : 'g:\\ MXD_files\\*.*'
是什么意思呢
|
|