Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Capture corrupt files and continue script

$
0
0
Hi All,

I am developing a script that walks a directory and sub-folders listing coverages, rasters and feature classes. Running successfully until it hits files that exist but not structured correctly / corrupted to be able to perform a describe function on.

I would like to capture these error files into a log file to check on them later, but have my script run to completition.

I have the following trying to capture error related files:

Code:

try:

<my code>

except arcpy.ExecuteError:
            arcpy.AddError(arcpy.GetMessage(2))
            f=open(r'D:\Temp\error.log', 'a')
            f.write(item + "\\" + fileset)
            f.close()

item represents path (e.g. "C:\Temp") and fileset is the file name (e.g. "data.shp").

Not sure what is happening as this seems to work elsewhere on the web I have seen referenced.

When I do a desc.SpatialReference.name will usually halt the script with the problem file.

I just need coding to detect problem spatial datasets, list them for later checking and move on.

Regards,

Craig

Viewing all articles
Browse latest Browse all 2485

Trending Articles