import os import arcpy workspace = r"C:\working\roger" output = r"C:\testlist.txt" def inventory_data(workspace, datatypes, output): """ Generates full path names under a catalog tree for all requested datatype(s). Parameters: workspace: string The top-level workspace that will be used. datatypes: string | list | tuple Keyword(s) representing the desired datatypes. A single datatype can be expressed as a string, otherwise use a list or tuple. See arcpy.da.Walk documentation for a full list. """ with open(output, "w") as outFile: for path, path_names, data_names in arcpy.da.Walk( workspace, datatype=datatypes): for data_name in data_names: outFile.write(os.path.join(path, data_name) + os.linesep) inventory_data(workspace, "Any", output)
import os import arcpy workspace = r"T:\test" output = r"H:\testlist.txt" def inventory_data(workspace, datatypes): """ Generates full path names under a catalog tree for all requested datatype(s). Parameters: workspace: string The top-level workspace that will be used. datatypes: string | list | tuple Keyword(s) representing the desired datatypes. A single datatype can be expressed as a string, otherwise use a list or tuple. See arcpy.da.Walk documentation for a full list. """ for path, path_names, data_names in arcpy.da.Walk( workspace, datatype=datatypes): for data_name in data_names: yield os.path.join(path, data_name) with open(output, "w") as outFile: for f in inventory_data(workspace, "Any"): outFile.write(f + os.linesep)
I'm new to Python. The 'workspace' variable is confusing to me. Do I need a file to be located at that location? Or should that point to my GIS DB server?
In this case, I think the workspace variable is simply where to start the searching. You could also look into using arcpy.da.Walk().
The workspace variable is the root directory you want it to search for spatial data. So if you set it to "C:/" it would check all folders and subfolders in the C drive for spatial data and write it to a report. If you have a particular folder within a drive say "D:/ForestryData" that has folders and subfolders to be checked and used that as the workspace it would check all folders and subfolders of "D:/ForestryData" for data. I'm not sure if you can point it at a database connection or not.
I work with Enterprise databases so I have to create SDE connections to datasets within databases. SQL Server. So I don't have a mapped drive letter that will do this. Is there an option for Enterprise level database settings?
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.