Thursday, 23 March 2017

arcpy - How to make a GIS inventory?


My office will be seeing a big change in its GIS section. This section has been operational since the 1980's and has a huge collection of GIS data (i.e., shapefiles, raster files, data, etc) but never been through any inventory. Now it will happen.


Is there any automated way to extract all the information about the GIS data (i.e., shapefile, arc-info coverage, layer file, *.mxd, gdb, raster file, and more) from a PC to an Excel file? The information may include date of creation, date last edited, folder or container name, etc.



Answer



Thanks artwork21 and Nathan W for your response. And yes Nathen's code made the magic.


import os, arcpy

#create blank text file
with open("C:\\Temp\\GISlayers.txt", "w") as txt:
for root, dirs, files in os.walk("C:\\Temp\\temp"):

for f in files:
#look for shapefiles
if f.endswith('.shp'):
desc = arcpy.Describe(root + "\\" + f)
#write info to text file
txt.write(desc.name + "," + desc.catalogPath + "\n")

#look for file geodatabases
if f.endswith('.gdb'):
desc = arcpy.Describe(root)

for child in desc.children:
#write info to text file
txt.write(child.name + "," + child.path + "\n")

#look for layer files
if f.endswith('.lyr'):
desc = arcpy.Describe(root + "\\" + f)
#write info to text file
txt.write(desc.name + "," + desc.catalogPath + "\n")


#look for img file
if f.endswith('.img'):
desc = arcpy.Describe(root + "\\" + f)
#write info to text file
txt.write(desc.name + "," + desc.catalogPath + "\n")

Only file name, and location. The pc i'll be working with has lots of coverage (the arc-info file) file, will it work on them too?


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...