Hello
I am trying to rename shapefile to current date like this dd_02112022.zip
I am created zip file but I can't find out how to rename shapefile or feature class before zipping all together.
any python code or arcpy to rename and add current date.
Best,
many ways to generate the date string, here is one. I assume you have the rest in hand
from datetime import datetime as dt
n = dt.now()
"-".join([f"{i}" for i in [n.year, n.month, n.day]])
'2022-2-11'
This worked for me using the rename_management function and a shapefile. It took a shapefile name Kim.shp and renamed it to append todays date... the code to create the zip file works to, but it creates a zip file that starts at the base of the path... if that makes sense.
Hello @KimGarbade
I don't way but I run your code on jupyter notebook on Arcpro and works fine when I am trying to run on PyScripter I am getting error
#rename shapefile
txtFileNameWithExt = "op.shp"
txtFileNameNoExt = f"{os.path.splitext(txtFileNameWithExt)[0]}_{datetime.datetime.now():%Y_%m_%d}"
arcpy.env.workspace = my_Path
arcpy.Rename_management(txtFileNameWithExt,f"{txtFileNameNoExt}.shp")
you are missing a matching }
I checked and I don't miss anything
seems "f" doesn't work here
txtFileNameNoExt = f"{os.path.splitext(txtFileNameWithExt)[0]}_{datetime.datetime.now():%Y_%m_%d}"
^
SyntaxError: invalid syntax
also here
arcpy.env.workspace = my_Path
arcpy.Rename_management(txtFileNameWithExt,f"{txtFileNameNoExt}.shp")
"f" substitution only works in Python 3.6 and above.... might have to use an older substitution method. You could try % formatting... its an older way to do string substitution in Python.
I wrote mine in Spyder... I don't know much about PyScripter, but maybe it needs a reference to the 'os' or 'datetime' modules