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"
Solved! Go to Solution.
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
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
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!