使用python读取projectwise文件夹

2024-04-20 12:13:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图链接到projectwise中的一个文件夹,其中包含mxds,我需要获取功能类列表,但python控制台中的目录不正确。不过,在windows中直接尝试路径是可行的,它会将我直接带到projectwise中的文件夹。我不确定我是否没有在python中正确读取文件夹

import arcpy, os  
#this is the projectwise folder 
path = r"pw:\\up114.dataonline.local:PWM\Documents\60439-Stone Tech\300 Non Deliverables\Management Team\G\Fig"
#Update the .csv file name below(stored in the folder where python script is
 f = open('inventory.csv', 'w')  
 f.write("Title, Layer, Dataset Path" + "\n")  
for root, dirs, files in os.walk(path):  
    for fileName in files:  
        basename, extension = os.path.splitext(fileName)  
#Write the information for all .mxd's with broken data sources  
        if extension == ".mxd":  
            fullPath = os.path.join(root, fileName)  
            mxd = arcpy.mapping.MapDocument(fullPath)  
            Layers = arcpy.mapping.ListLayers(mxd)
            for Layer in Layers:
                if Layer.supports("DATASOURCE"):
                    if Layer.isFeatureLayer or Layer.isGroupLayer: 
                        print "Layer: " + Layer.name
                        f.write(fileName + ", "  + Layer.name + ", " + Layer.dataSource +  ","  "\n")  
                    else:
                        f.write("\n")


f.close()  

print 'Completed creating list'

Tags: thepathnamein文件夹layerforif