ArcToolBox Script Multiple File Input problems

640
3
04-03-2019 10:48 AM
RobertHarvey
New Contributor

I continue to have problems writing an ArcPro ArcToolBox tool script that takes as input 'multiple' files to be geoprocessed. To get right to the point, here is a code snippet:

def main():

   gzipFiles = arcpy.GetParameterAsText(0)

   myGzipFiles = gzipFiles.split(';')

   for myGzipFileThatReallyExists in myGzipFiles:

      gz = gzip.open(myGzipFileThatReallyExists, 'r')   <-------FileNotFoundError..blah...blah...

      gzContent = gz.read()   

      doMyGeoProcessing(gzContent)                 

      gz.close()

The script fails in the above "gzip.open" statement with:

FileNotFoundError: [Errno 2] No such file or directory: "'C:\\MyFileReallyDoesExistHere.csv.gz'".

Note, I realize that there might be an issue with formatting the path to the gzip file in the loop (gzipFile), but I have exhausted trying everything with string.format, pathlib, os.path, etc. Note 2, the code works when I deselect the File input parameter "Multiple values" and adjust the code to:

def main():

   gzipFile = arcpy.GetParameterAsText(0)

   gz = gzip.open(gzipFile, 'r')   <------- WORKS !?!?!?!?

   gzContent = gz.read()   

   doMyGeoProcessing(gzContent)                 

   gz.close()

This problem is very similar to problems I encountered decompressing KMZ files IN A FOR LOOP using:

zipfile..ZipFile(kmzFileThatReallyDoesExistVariable, 'r')   <---------FileNotFounError...blah....blah

Any suggestion is greatly appreciated. This shouldn't be this hard to do!!!!

V/R

0 Kudos
3 Replies
DylanHarwell
Occasional Contributor

I have run into path problems in custom toolbox scripts too. Have you tried printing paths to the tool dialog window as it runs? Have it print your paths to see if that is an issue. I usually use os.path in my scripts, and have run into an odd situation where I had to do something like os.path.abspath(os.path.join(path1, path2)) to get the slashes all going the same direction!

RobertHarvey
New Contributor

Thanks Dylan,

I am printing debug statements out during the decompression. The path 'slashes' appear to be correct. I will try and use os.path.abspath etc again.

V/R

0 Kudos
RobertHarvey
New Contributor

I failed to mention that this problem manifests only in ArcPro. When running in ArcMap, the cited code works. There is no question that this is a bug in ArcPro.

0 Kudos