I am trying to move raster files from one location to another.

By using the function: ListRasters (arcpy), I can get the list of rasters to be moved, but the problem is that even corrupted rasters are listed by this function. Actually if you use ArcCatalog and navigate to the folder, everything seems to be right and valid and invalid rasters are listed together but if you try to preview a corrupted one, it will pop-up:

enter image description here

In detail, I am talking here about several corrupted Esri GRID rasters. How to differentiate them?

So, when I use the function: Copy (Data Management), arcpy rises an error when trying to move an invalid GRID.

I was trying to solve this issue by using any of the properties of the Describe function: Describe object properties (arcpy), and getting any difference between the valid ones and the invalid ones, but this function raises an error on invalid datasets, so it cannot be used.

for raster in arcpy.ListRasters():
  desc = arcpy.Describe(raster)

Runtime error 
Traceback (most recent call last):
  File "<string>", line 4, in <module>
  File "c:\program files\arcgis\desktop10.1\arcpy\arcpy\__init__.py", line 1200, in Describe
return gp.describe(value)
  File "c:\program files\arcgis\desktop10.1\arcpy\arcpy\geoprocessing\_base.py", line 374, in describe
self._gp.Describe(*gp_fixargs(args, True)))
IOError: "raster" does not exist

Any ideas?


Use try-except in your code.

for raster in arcpy.ListRasters():
        desc = arcpy.Describe(raster)
        'Do nothing, just skip to the next

If this isn't working you need to check if the raster exists first.

  • Good!, working so far, but is there any way of asking specifically for an invalid raster? is there any arcpy function to check this? – Web-GIS entrepreneur Jan 7 '16 at 11:09
  • 1
    There are an infinite number if ways to destroy data, and no reliable ways to verify integrity. Catching exceptions on failure is your only option, and it will only capture some classes of error. – Vince Jan 7 '16 at 11:59
  • Errors, or invalid rasters are 'catched' by the except statement. You can handle them over there. – Stefan Jan 7 '16 at 12:00
  • 1
    Yes, and not..The except statement will tell you that the "raster" does not exist as in the example above, but it is not true at all. It's there but it is not readable, that's different. – Web-GIS entrepreneur Jan 7 '16 at 12:18
  • If it's listed in the catalog, then it's "there" but if it fails an exists or fails to describe, then it's corrupt. – Vince Jan 7 '16 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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