列出Arcpy中文件夹内的文件?

时间:2018-08-10 09:29:19

标签: python arcpy

我已经完成了在环境中列出shapefile的过程,但是它返回了环境中的文件夹名称:

arcpy.env.workspace  = r"C:\Users\user\Desktop\results"
dd= arcpy.ListFiles()
for i in dd:
    print(i)

给予:

shapesfiles1  
shapefiles2

如何打印这些文件夹中的内容?

1 个答案:

答案 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))