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.
<SPAN class="comment token"># # much more in the script....written for 10.2.x +, but might give </SPAN> <SPAN class="comment token"># you some ideas for 10.1</SPAN> <SPAN class="keyword token">import</SPAN> arcpy <SPAN class="keyword token">import</SPAN> os <SPAN class="comment token"># shows messages for python window or tool, but does not log</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">myMsgs</SPAN><SPAN class="punctuation token">(</SPAN>message<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>AddMessage<SPAN class="punctuation token">(</SPAN>message<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>message<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">mySleep</SPAN><SPAN class="punctuation token">(</SPAN>secs<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> myMsgs<SPAN class="punctuation token">(</SPAN><SPAN class="string token">" zzz...sleeping {0} seconds to allow network file status to catch up...."</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>secs<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> time<SPAN class="punctuation token">.</SPAN>sleep<SPAN class="punctuation token">(</SPAN>secs<SPAN class="punctuation token">)</SPAN> pathSourceFGDB <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>r<SPAN class="string token">"\\{0}\shareDrive\data"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>Myserver<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> pathTargetFGDB <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">(</SPAN>r<SPAN class="string token">"\\{0}\shareDrive\data"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>Myserver<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> updateFGDB <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>pathTargetFGDB<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Master_update.gdb"</SPAN><SPAN class="punctuation token">)</SPAN> currentFGDB <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>pathTargetFGDB<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"myCurrentName.gdb"</SPAN><SPAN class="punctuation token">)</SPAN> newFGDB <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>pathTargetFGDB<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"myNewName.gdb"</SPAN><SPAN class="punctuation token">)</SPAN> baseUpdateFGDB <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>basename<SPAN class="punctuation token">(</SPAN>updateFGDB<SPAN class="punctuation token">)</SPAN> baseCurrentFGDB <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>basename<SPAN class="punctuation token">(</SPAN>currentFGDB<SPAN class="punctuation token">)</SPAN> baseNewFGDB <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>basename<SPAN class="punctuation token">(</SPAN>newFGDB<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">if</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Exists<SPAN class="punctuation token">(</SPAN>currentFGDB<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># Rename _current to _currentBAK</SPAN> <SPAN class="comment token"># clearWSLocks(currentFGDB) # needs admin, can't use</SPAN> myMsgs<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"\n Attempting to Rename {0} to {1}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>baseCurrentFGDB<SPAN class="punctuation token">,</SPAN>baseBackupFGDB<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># trying to rename the _current as the backup, and copy _update to _current</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Rename_management<SPAN class="punctuation token">(</SPAN>currentFGDB<SPAN class="punctuation token">,</SPAN> newFGDB<SPAN class="punctuation token">)</SPAN> mySleep<SPAN class="punctuation token">(</SPAN><SPAN class="number token">30</SPAN><SPAN class="punctuation token">)</SPAN> myMsgs<SPAN class="punctuation token">(</SPAN><SPAN class="string token">" Rename successful"</SPAN><SPAN class="punctuation token">)</SPAN> myMsgs<SPAN class="punctuation token">(</SPAN><SPAN class="string token">" Attempting to copy {0} to {1}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>baseUpdateFGDB<SPAN class="punctuation token">,</SPAN> baseCurrentFGDB<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Copy_management<SPAN class="punctuation token">(</SPAN>updateFGDB<SPAN class="punctuation token">,</SPAN> currentFGDB<SPAN class="punctuation token">)</SPAN> mySleep<SPAN class="punctuation token">(</SPAN><SPAN class="number token">30</SPAN><SPAN class="punctuation token">)</SPAN> updateComplete <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN> myMsgs<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"\n Copy successful. (note: 01)"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">except</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># if rename doesn't work, most likely some files open. Abort and restart services</SPAN> myMsgs<SPAN class="punctuation token">(</SPAN><SPAN class="string token">" Since renaming {0} to {1} didn't work, might have locked files in _current folder.\n Abort and restart services."</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>baseCurrentFGDB<SPAN class="punctuation token">,</SPAN>baseNewFGDB<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> startStatusOK <SPAN class="operator token">=</SPAN> updateStopStartServices<SPAN class="punctuation token">(</SPAN>siteURL<SPAN class="punctuation token">,</SPAN> theToken<SPAN class="punctuation token">,</SPAN> updateServicesList<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"START"</SPAN><SPAN class="punctuation token">)</SPAN> updateComplete <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">False</SPAN> <SPAN class="comment token">#showStatus(statusINI, scriptNum, newValue = "ERROR: not done. Fix and rerun")</SPAN> <SPAN class="comment token">#sys.exit()</SPAN> updateStatusAndExit<SPAN class="punctuation token">(</SPAN>statusINI<SPAN class="punctuation token">,</SPAN> scriptNum<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># but just in case it doesn't exit, copy _current to backup</SPAN> myMsgs<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"\n Attemping to copy {0} to {1}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>baseCurrentFGDB<SPAN class="punctuation token">,</SPAN>baseNewFGDB<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Copy_management<SPAN class="punctuation token">(</SPAN>currentFGDB<SPAN class="punctuation token">,</SPAN> backupFGDB<SPAN class="punctuation token">)</SPAN> myMsgs<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"\n Copy successful."</SPAN><SPAN class="punctuation token">)</SPAN> mySleep<SPAN class="punctuation token">(</SPAN><SPAN class="number token">30</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">except</SPAN><SPAN class="punctuation token">:</SPAN> myMsgs<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"\n Copy of {0} to {1} didn't work. Restart services."</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>basename<SPAN class="punctuation token">(</SPAN>currentFGDB<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">try</SPAN><SPAN class="punctuation token">:</SPAN> myMsgs<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"\n Attemping to delete {0}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>baseCurrentFGDB<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> myMsgs<SPAN class="punctuation token">(</SPAN><SPAN class="string token">" Deleting {0}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>baseCurrentFGDB<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Delete_management<SPAN class="punctuation token">(</SPAN>currentFGDB<SPAN class="punctuation token">)</SPAN> mySleep<SPAN class="punctuation token">(</SPAN><SPAN class="number token">30</SPAN><SPAN class="punctuation token">)</SPAN> corruptFgdb <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Exists<SPAN class="punctuation token">(</SPAN>currentFGDB<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">if</SPAN> corruptFgdb<SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># if the folder still exists, the delete corrupted the fgdb</SPAN> myMsgs<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"didn't work...copy the files back before restarting...."</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># how can I copy the files from _update to _current that got deleted?</SPAN> restoreFromUpdate <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>listdir<SPAN class="punctuation token">(</SPAN>updateFGDB<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">for</SPAN> restoreFile <SPAN class="keyword token">in</SPAN> restoreFromUpdate<SPAN class="punctuation token">:</SPAN> srcfile <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>updateFGDB<SPAN class="punctuation token">,</SPAN> restoreFile<SPAN class="punctuation token">)</SPAN> dstfile <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>currentFGDB<SPAN class="punctuation token">,</SPAN> restoreFile<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="operator token">not</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>exists<SPAN class="punctuation token">(</SPAN>dstfile<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN> shutil<SPAN class="punctuation token">.</SPAN>copy<SPAN class="punctuation token">(</SPAN>srcfile<SPAN class="punctuation token">,</SPAN> currentFGDB<SPAN class="punctuation token">)</SPAN> myMsgs<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"copied {0}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>srcfile<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN> myMsgs<SPAN class="punctuation token">(</SPAN><SPAN class="string token">" {0} already exists"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>dstfile<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># restart services and abort...still using older fgdb</SPAN> startStatusOK <SPAN class="operator token">=</SPAN> updateStopStartServices<SPAN class="punctuation token">(</SPAN>siteURL<SPAN class="punctuation token">,</SPAN> theToken<SPAN class="punctuation token">,</SPAN> updateServicesList<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"START"</SPAN><SPAN class="punctuation token">)</SPAN> updateComplete <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">False</SPAN> <SPAN class="comment token">#showStatus(statusINI, scriptNum, newValue = "ERROR: not done. Fix and rerun")</SPAN> <SPAN class="comment token">#sys.exit()</SPAN> updateStatusAndExit<SPAN class="punctuation token">(</SPAN>statusINI<SPAN class="punctuation token">,</SPAN> scriptNum<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># # much more in the script</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
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.
<SPAN class="operator token">>></SPAN><SPAN class="operator token">></SPAN> r <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'\\cordata\Universal\R_Allen\test\StormJetting.gdb'</SPAN> <SPAN class="operator token">>></SPAN><SPAN class="operator token">></SPAN> r <SPAN class="string token">'\\\\cordata\\Universal\\R_Allen\\test\\StormJetting.gdb'</SPAN> <SPAN class="operator token">>></SPAN><SPAN class="operator token">></SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Rename_management<SPAN class="punctuation token">(</SPAN>r<SPAN class="punctuation token">,</SPAN><SPAN class="string token">'testing.gdb'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token"><</SPAN>Result <SPAN class="string token">'testing.gdb'</SPAN><SPAN class="operator token">></SPAN> <SPAN class="operator token">>></SPAN><SPAN class="operator token">></SPAN> t <SPAN class="operator token">=</SPAN> r<SPAN class="string token">'U:\R_Allen\test\testing.gdb'</SPAN> <SPAN class="operator token">>></SPAN><SPAN class="operator token">></SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Rename_management<SPAN class="punctuation token">(</SPAN>t<SPAN class="punctuation token">,</SPAN><SPAN class="string token">'testing2.gdb'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token"><</SPAN>Result <SPAN class="string token">'testing2.gdb'</SPAN><SPAN class="operator token">></SPAN> <SPAN class="operator token">>></SPAN><SPAN class="operator token">></SPAN> t <SPAN class="operator token">=</SPAN> <SPAN class="string token">'U:\\R_Allen\\test\\testing.gdb'</SPAN> <SPAN class="operator token">>></SPAN><SPAN class="operator token">></SPAN> t <SPAN class="string token">'U:\\R_Allen\\test\\testing.gdb'</SPAN> <SPAN class="operator token">>></SPAN><SPAN class="operator token">></SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Rename_management<SPAN class="punctuation token">(</SPAN>t<SPAN class="punctuation token">,</SPAN><SPAN class="string token">'testing.gdb'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">>></SPAN><SPAN class="operator token">></SPAN> MappingTemplate_gdb <SPAN class="operator token">=</SPAN> <SPAN class="string token">'U:\\R_Allen\\test\\testing.gdb'</SPAN> <SPAN class="operator token">>></SPAN><SPAN class="operator token">></SPAN> MappingTemplate_RenameTyped_gdb <SPAN class="operator token">=</SPAN> <SPAN class="string token">'U:\\R_Allen\\test\\testing_retyped.gdb'</SPAN> <SPAN class="operator token">>></SPAN><SPAN class="operator token">></SPAN> arcpy<SPAN class="punctuation token">.</SPAN>Rename_management<SPAN class="punctuation token">(</SPAN>MappingTemplate_gdb<SPAN class="punctuation token">,</SPAN> MappingTemplate_RenameTyped_gdb<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Workspace"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token"><</SPAN>Result <SPAN class="string token">'U:\\R_Allen\\test\\testing_retyped.gdb'</SPAN><SPAN class="operator token">></SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
R_
Also good to know rename_management doesn't work on geodatabases. the help
isn't explicit about it. thanks
Thanks yeah it's 10.1. I need to do it in a script or model so I can loop
through hundreds of them.
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.
Follow these steps to rename a file or personal geodatabase:
If the folder connection does not already exist, add one to the Catalog tree.
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.
4 & 1/2 years later the first reply is someone having exactly the same problem...
will keep googling
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.