在 Arcpy 中列出文件夹内的文件?
List files inside folders in Arcpy?
我已经完成了在环境中列出 shapefile 的程序,但是 returns 环境中的文件夹名称:
arcpy.env.workspace = r"C:\Users\user\Desktop\results"
dd= arcpy.ListFiles()
for i in dd:
print(i)
给出:
shapesfiles1
shapefiles2
如何打印这些文件夹中的内容?
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))
我已经完成了在环境中列出 shapefile 的程序,但是 returns 环境中的文件夹名称:
arcpy.env.workspace = r"C:\Users\user\Desktop\results"
dd= arcpy.ListFiles()
for i in dd:
print(i)
给出:
shapesfiles1
shapefiles2
如何打印这些文件夹中的内容?
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))