To better organize data, I want to create a dictionary that takes a directory path as an argument and groups the items by datatype (for example: u'ShapeFile': ['abc.shp']). However, I run into an issue every time I try to use the describe object (desc) to classify them by dataType:
import arcpy, os, sys
inputDir = sys.argv[1]
fileList = os.listdir(inputDir)
fileDict= {}
for f in fileList:
print f
desc = arcpy.Describe(f)
print "Data Type: " + desc.dataType
Every time I use this method, it throws an IOError: saying that the first item it tries to use the describe.dataType on doesn't exist.
How do I incorporate the describe function into the code so that it pulls out the dataType?
print(fileList)
immediately after setting it so that you can see the first item in it? If so, then what is that first item?hasattr
desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-functions/… but I would usearcpy.ListDatasets
instead ofos.listdir
dataType
should always be present. Could you post the fullIOError
?