python script tool - files in given directory not found

2820
13
Jump to solution
04-28-2017 05:05 AM
Nicole_Ueberschär
Esri Regular Contributor

Hello friendly people, 

I have written a python script to split up text files. It has an input folder (and an output folder) that I refer to in the beginning: 

hardcoded version: _location_for_tables = r"C:\data\2017\LakeKivu\Data\Python_testing\python\Pilot\source"
script tool version:  _location_for_tables = arcpy.GetParameterAsText(0)

When I execute the script in Pyscripter and in the command window, also in the python window in ArcGIS, everything runs as expected. But when I run it as a script tool it doesn't find my files. I tried it with the hardcoded path in the script and with an input field where I selected the (same) folder - no difference. I tried to put the path variables in my main() function and in the beginning of my script - no difference. 

The only error message I receive is my defined message when the list of files is empty. 

Has anyone an idea where the problem is? Please let me know if you need more details. Thanks in advance!

Tags (1)
0 Kudos
13 Replies
DanPatterson_Retired
MVP Emeritus

and that was with path lines uncommented and the getparameterastext lines commented out?  

0 Kudos
Nicole_Ueberschär
Esri Regular Contributor

I tried it both, with folder path names in the script and as parameters. 

0 Kudos
DanPatterson_Retired
MVP Emeritus
ListFiles=arcpy.ListFiles("*.txt")

maybe rename your ListFiles variable incase it is conflicting with arcpy's ListFiles (and that's all I can think of)
0 Kudos
Nicole_Ueberschär
Esri Regular Contributor

Thank you both for looking into this. I found the problem: I unchecked the "Run in process" Checkbox when creating the tool. So in case someone else is facing similar problems: Make sure to leave the "Run in process" checkbox checked!

(I had a colleague also looking at this and he didn't have a clue why it would not run without this checkbox though...)

0 Kudos