我已经完成了在环境中列出shapefile的过程,但是它返回了环境中的文件夹名称:
arcpy.env.workspace = r"C:\Users\user\Desktop\results"
dd= arcpy.ListFiles()
for i in dd:
print(i)
给予:
shapesfiles1
shapefiles2
如何打印这些文件夹中的内容?
答案 0 :(得分:1)
arcpy.da.Walk()
可以做到,documentation
这将列出找到的所有文件:
import arcpy
import os
arcpy.env.workspace = r"C:\Users\user\Desktop\results"
walk = arcpy.da.Walk(datatype="FeatureClass")
for dir_path, dir_names, file_names in walk:
for filename in file_names:
print(filename)
或者如果您想要完整的路径:
import arcpy
import os
arcpy.env.workspace = r"C:\Users\user\Desktop\results"
walk = arcpy.da.Walk(datatype="FeatureClass")
for dir_path, dir_names, file_names in walk:
for filename in file_names:
print(os.path.join(dir_path, filename))