4 & 1/2 years later the first reply is someone having exactly the same problem...
will keep googling
Are you trying to rename a file gdb? Are you stilll using 10.0 or a newer version? This is from the 10.3 help
Might want to look at Rename a geodatabase—Help | ArcGIS for Desktop
Follow these steps to rename a file or personal geodatabase:
- Start ArcMap and open the Catalog window, or open ArcCatalog.
- Navigate to the folder location of the geodatabase you want to rename.
If the folder connection does not already exist, add one to the Catalog tree.
- Right-click the geodatabase and click Rename.
- Type a new name for the geodatabase.
- Press Enter when you are finished.
re: Rename_management
Rename—Help | ArcGIS for Desktop
Changes the name of a dataset. This includes a wide variety of data types, among them feature dataset, raster, table, and shapefile
EDIT:
doesn't rename a GDB.
It doesn't specifically say it will work for gdb, but I have used it....I think the key is to use full path names to the data.
Thanks yeah it's 10.1. I need to do it in a script or model so I can loop
through hundreds of them.
Also good to know rename_management doesn't work on geodatabases. the help
isn't explicit about it. thanks
I don't have 10.1 to test, but in 10.2.1 Rename_management works just fine to rename a FGDB across network using UNC or mapped drives.
Tested a few path formats, as well as variables vs. hardcoded. Last example is similar to OP.
The fact that it works for you on local drive but not network suggests that it should work.
If not, a FGDB is just a folder and can be renamed with os.rename. Just need to make sure nothing is connected to the FGDB, as both these methods will fail if there are lock files present.
>>> r = r'\\cordata\Universal\R_Allen\test\StormJetting.gdb'
>>> r
'\\\\cordata\\Universal\\R_Allen\\test\\StormJetting.gdb'
>>> arcpy.Rename_management(r,'testing.gdb')
<Result 'testing.gdb'>
>>> t = r'U:\R_Allen\test\testing.gdb'
>>> arcpy.Rename_management(t,'testing2.gdb')
<Result 'testing2.gdb'>
>>> t = 'U:\\R_Allen\\test\\testing.gdb'
>>> t
'U:\\R_Allen\\test\\testing.gdb'
>>> arcpy.Rename_management(t,'testing.gdb')
>>> MappingTemplate_gdb = 'U:\\R_Allen\\test\\testing.gdb'
>>> MappingTemplate_RenameTyped_gdb = 'U:\\R_Allen\\test\\testing_retyped.gdb'
>>> arcpy.Rename_management(MappingTemplate_gdb, MappingTemplate_RenameTyped_gdb, "Workspace")
<Result 'U:\\R_Allen\\test\\testing_retyped.gdb'>
R_
My ipad ate my response below a couple days ago. I also have bee able to get the rename to work....I edited my above response, since I think it some down to making sure to use full pathnames for the .gdb, not relative names. That is a guess on my part, not verified, but I think that is how I got mine version to work
----
In 10.3, I do actually use the arcpy.Rename_management(inFGB, newName) to rename file gdb's, even though the help says it won't work. The critical thing it you need to make sure there are no locks on the files
This is a small snippet of a much larger script that is used to replace an entire fgdb that is use in ArcGIS Server Services, so you will see some mention of services, but the rename and the try..except are what I'm pointing out. Again, this is written in 10.2.x+, so would have to be looked at and tested to see if it would work in 10.1. I have a few utilities (not included) I am using to make sure there aren't any locked filed, but hey don't catch everything. In my case, it is because of the services, mainly.
# # much more in the script....written for 10.2.x +, but might give
# you some ideas for 10.1
import arcpy
import os
# shows messages for python window or tool, but does not log
def myMsgs(message):
arcpy.AddMessage(message)
print(message)
def mySleep(secs):
myMsgs(" zzz...sleeping {0} seconds to allow network file status to catch up....".format(secs))
time.sleep(secs)
pathSourceFGDB = (r"\\{0}\shareDrive\data".format(Myserver))
pathTargetFGDB = (r"\\{0}\shareDrive\data".format(Myserver))
updateFGDB = os.path.join(pathTargetFGDB, "Master_update.gdb")
currentFGDB = os.path.join(pathTargetFGDB, "myCurrentName.gdb")
newFGDB = os.path.join(pathTargetFGDB, "myNewName.gdb")
baseUpdateFGDB = os.path.basename(updateFGDB)
baseCurrentFGDB = os.path.basename(currentFGDB)
baseNewFGDB = os.path.basename(newFGDB)
if arcpy.Exists(currentFGDB):
# Rename _current to _currentBAK
# clearWSLocks(currentFGDB) # needs admin, can't use
myMsgs("\n Attempting to Rename {0} to {1}".format(baseCurrentFGDB,baseBackupFGDB))
try: # trying to rename the _current as the backup, and copy _update to _current
arcpy.Rename_management(currentFGDB, newFGDB)
mySleep(30)
myMsgs(" Rename successful")
myMsgs(" Attempting to copy {0} to {1}".format(baseUpdateFGDB, baseCurrentFGDB))
arcpy.Copy_management(updateFGDB, currentFGDB)
mySleep(30)
updateComplete = True
myMsgs("\n Copy successful. (note: 01)")
except: # if rename doesn't work, most likely some files open. Abort and restart services
myMsgs(" Since renaming {0} to {1} didn't work, might have locked files in _current folder.\n Abort and restart services.".format(baseCurrentFGDB,baseNewFGDB))
startStatusOK = updateStopStartServices(siteURL, theToken, updateServicesList, "START")
updateComplete = False
#showStatus(statusINI, scriptNum, newValue = "ERROR: not done. Fix and rerun")
#sys.exit()
updateStatusAndExit(statusINI, scriptNum)
try: # but just in case it doesn't exit, copy _current to backup
myMsgs("\n Attemping to copy {0} to {1}".format(baseCurrentFGDB,baseNewFGDB))
arcpy.Copy_management(currentFGDB, backupFGDB)
myMsgs("\n Copy successful.")
mySleep(30)
except:
myMsgs("\n Copy of {0} to {1} didn't work. Restart services.".format(os.path.basename(currentFGDB)))
try:
myMsgs("\n Attemping to delete {0}".format(baseCurrentFGDB))
myMsgs(" Deleting {0}".format(baseCurrentFGDB))
arcpy.Delete_management(currentFGDB)
mySleep(30)
corruptFgdb = arcpy.Exists(currentFGDB)
if corruptFgdb: # if the folder still exists, the delete corrupted the fgdb
myMsgs("didn't work...copy the files back before restarting....")
# how can I copy the files from _update to _current that got deleted?
restoreFromUpdate = os.listdir(updateFGDB)
for restoreFile in restoreFromUpdate:
srcfile = os.path.join(updateFGDB, restoreFile)
dstfile = os.path.join(currentFGDB, restoreFile)
if not os.path.exists(dstfile):
shutil.copy(srcfile, currentFGDB)
myMsgs("copied {0}".format(srcfile))
else:
myMsgs(" {0} already exists".format(dstfile))
# restart services and abort...still using older fgdb
startStatusOK = updateStopStartServices(siteURL, theToken, updateServicesList, "START")
updateComplete = False
#showStatus(statusINI, scriptNum, newValue = "ERROR: not done. Fix and rerun")
#sys.exit()
updateStatusAndExit(statusINI, scriptNum)
# # much more in the script