Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a script which scans a directory and outputs basic raster data information such as the file name, format, number of bands, and etc. I need a way to make it so if the directory does not contain raster data (i.e., anything other than raster data), a message is displayed stating that the directory doesn't have the correct data type.

I know ArcPy has a Describe() function that I could use to determine the type of data in a folder, but am not sure how to implement it. This is what I have so far:

rasterList = arcpy.ListRasters("*", "ALL")
filesType = arcpy.DataType('RasterDataset') # Can use `DatasetType` as well. 
                                            # I've tested this function to describe
                                            # raster data and ArcPy prints out
                                            # 'RasterDataset', that is why I have it 
                                            # there in the brackets.
for name in rasterList:
    if rasterList == filesType:
        print ("\nFilename:"), name
        print ("This directory does not contain any raster data.")

Any suggestions?

share|improve this question
up vote 16 down vote accepted

How about something simple like:

if len(rasterList) == 0:
    print ("This directory does not contain any raster data.")
    # Your raster processing code

The len() function calculates the length of the returned string/list, so if it returns 0 then you know nothing in the folder matched the criterion (in this case, being a raster). This way, if the folder contains any rasters (even if not every file is a raster) they will be processed.

share|improve this answer
Thanks nmpeterson! That was it. I knew I was missing something simple. Can't believe I didn't think of the len() function. – mapr Nov 19 '11 at 23:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.