Why will python script work standalone but not in Model Builder?

276
2
Jump to solution
10-09-2018 07:28 PM
LindsayRaabe_FPCWA
Regular Contributor

I've got a pretty simple script that looks for the latest/newest file in a folder and copies it into a new location. The script works fine when run through a python GUI, but when run as a part of an Arc model, fails. Can someone translate the error for me? I don't understand why this is happening?

import glob
import os
import shutil
import time

date = time.strftime("%Y-%m-%d")
dst = "//10.253.2.161/cddp/Bunbury Use Only/GeoMasterPatchArchives/" + date

list_of_files = glob.glob('//gis/Geomaster/*.bak') # * means all if need specific format then *.csv
latest_file = max(list_of_files, key=os.path.getctime)
shutil.copy(latest_file, dst)
print latest_file + " copied to backup folder"

Results of running the script as part of an Arc model

Lindsay Raabe
Forest Products Commission WA
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
DanPatterson_Retired
MVP Esteemed Contributor

max(list of files...  is empty

os.path.getctime is the key file (most recently added?)

So I am guessing that this path '//gis/Geomaster/*.bak

can't be found when run through the model, but can be found in the python environment because you set it?

Try the full path

View solution in original post

2 Replies
DanPatterson_Retired
MVP Esteemed Contributor

max(list of files...  is empty

os.path.getctime is the key file (most recently added?)

So I am guessing that this path '//gis/Geomaster/*.bak

can't be found when run through the model, but can be found in the python environment because you set it?

Try the full path

LindsayRaabe_FPCWA
Regular Contributor

I think it must have been the pathway. It was meant to be a complete path but I think the "gis" part was an alternative to the actual path of "bun-gis-01". I tweaked it and it worked so hopefully it keeps working. Thanks! 

Lindsay Raabe
Forest Products Commission WA
0 Kudos