Select to view content in your preferred language

Problem with Importing Exchange files while using an infile loop

632
2
05-16-2012 09:37 AM
BenSloboda
Emerging Contributor
Hi! I have a python script that's supposed to walk through a directory and convert any e00 files, while renaming them with a date/time stamp. The following code works:

# Import arcpy module
import arcpy

# Local variables:
q3710583_e00 = "C:\\Data\\ExchangeFiles\\q3710583.e00"
ExchangeFiles = "C:\\Data\\ExchangeFiles"

# Process: Import from E00
arcpy.ImportFromE00_conversion(q3710583_e00, ExchangeFiles, "q37105830")


The following code does NOT work:

import arcpy, os, ctypes, datetime

workspace="C:\\Data\\ExchangeFiles"

now=datetime.datetime.now()
count = 0
for infile in os.listdir(workspace):
    fileName, fileExtension = os.path.splitext(infile)
    if (fileExtension == '.e00'):
        arcpy.ImportFromE00_conversion(infile, workspace, "exchangeFile"+str(now.month)+"."+str(now.day)+"."+str(now.year))
    else:
        count += 1
        print str(count) + " files not converted"
    



I feel that the for loop is working, but the arcpy conversion fails every time with the following error:

Traceback (most recent call last):
File "C:/PythonScripts/WalkE00ThroughFolder.py", line 12, in <module>
arcpy.ImportFromE00_conversion(infile, workspace, "exchangeFile"+str(now.month)+"."+str(now.day)+"."+str(now.year))
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\conversion.py", line 1054, in ImportFromE00
raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Input interchange file: Dataset q3710583.e00 does not exist or is not supported
Failed to execute (ImportFromE00).

There is nothing in my test folder except three e00 files, and I made sure to delete any extraneous files before attempting to run the code. If there is a better way to search through a folder and pull out specific files for conversion, I'm all ears! Or if there's something simply wrong in my code, I'd love to have someone tell me.

Thanks!

-Ben S.
Tags (2)
0 Kudos
2 Replies
MathewCoyle
Honored Contributor
You have a couple problems.

1) Coverage names cannot be over 13 characters.
2) the infile parameter does not reference workspaces, it must be a full path

Read this for more information.
http://support.esri.com/en/knowledgebase/techarticles/detail/21052
0 Kudos
BenSloboda
Emerging Contributor
It's true!  The file name was too long for the output file, and the input file needed to be modified to include the full path.  See below for success story, and thank you!


import arcpy, os, ctypes, datetime

workspace="C:\\Data\\ExchangeFiles"

now=datetime.datetime.now()
count = 0
for infile in os.listdir(workspace):
    fileName, fileExtension = os.path.splitext(infile)
    if (fileExtension == '.e00'):
        arcpy.ImportFromE00_conversion(workspace +"\\"+ infile, workspace, fileName+"xxx")
    else:
        count += 1
        print str(count)+" files not converted"
    
box = ctypes.windll.user32.MessageBoxW
box(0, u'This script finished running at '+str(now), u"Success!", 0)
print "This script is finished running"


0 Kudos