datetime - simple renaming of file inside script keeping prefix -
i know there other questions renaming, have looked @ bunch, code won't work. have seen os python definitions.
basically code below part of larger script in gis running. have created geodatabase called permits.gdb , run necessary processing on data, want rename time stamp on backup purposes.
i getting errors file can't found... created in c:\test\permits.gdb know exists.... have seen several path examples ", ', /, , \, none seem work. path problem?
import time import os dir_path = os.path.normpath('c:/test') dir = os.listdir(dir_path) = time.strftime('%h%m%a%d%m%y') filename in dir: old_name = "permits.gdb" new_name = "baqp_permits_"+ +".gdb" os.rename(old_name, new_name) update: thank guys help! got work still throws error can't find specified file though , renames it. saving in location want , have combined rest of script (so file paths different now) here new code:
dir_path = os.path.normpath('l:\gis_admin\sde_update_backup\baqp_permits') dir = os.listdir(dir_path) = time.strftime('%h%m%a%d%m%y') filename in dir: old_name = dir_path + "\baqp_permits.gdb" new_name = dir_path + "\baqp_permits_"+ +".gdb" os.rename(old_name, new_name) and error:
traceback (most recent call last): file "c:\ndepgis\scripts\baqp_permits_aris_daily", line 28, in <module> os.rename(old_name, new_name) windowserror: [error 2] system cannot find file specified
try this:
import time import os dir_path = os.path.normpath('c:/test') dir = os.listdir(dir_path) = time.strftime('%h%m%a%d%m%y') filename in dir: old_name = dir_path + "/permits.gdb" new_name = dir_path + "/baqp_permits_"+ +".gdb" print "filename", filename print "old:", old_name print "new:", new_name os.rename(old_name, new_name) i don't think filename includes full path.
Comments
Post a Comment