arcpy.Rename_management - Does not work on network

4208
6
05-31-2012 12:19 PM
WayneLorshbough
New Contributor
Hello,

I have a model created from ModelBuilder to Rename a file geodatabase.  I have exported the model to python, but it does not work on the network.  It will work if I change the paths to C:\drive (local) NOT network.  I am using ArcInfo 10, service pack 4.

Please see python below.

Thanks for any help in advance.

Wayne.


# ---------------------------------------------------------------------------
# renameSdrviemappingTemplateTyped.py
# Created on: 2012-05-31 14:07:37.00000
#   (generated by ArcGIS/ModelBuilder)
# Description:
# ---------------------------------------------------------------------------

# Import arcpy module
import arcpy
arcpy.env.overwrite = True


# Local variables:
MappingTemplate_gdb = "S:\\WSL\\testing\\MappingTemplate.gdb"
MappingTemplate_RenameTyped_gdb = "S:\\WSL\\testing\\MappingTemplate_RenameTyped.gdb"

# Process: Rename
arcpy.Rename_management(MappingTemplate_gdb, MappingTemplate_RenameTyped_gdb, "Workspace")



Here are the results.

Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.

    ****************************************************************
    Personal firewall software may warn about the connection IDLE
    makes to its subprocess using this computer's internal loopback
    interface.  This connection is not visible on any external
    interface and no data is sent to or received from the Internet.
    ****************************************************************
   
IDLE 2.6.5      ==== No Subprocess ====
>>>
Traceback (most recent call last):
  File "C:\TEST\RenameModel\Script\renameSdrviemappingTemplateTyped.py", line 18, in <module>
    arcpy.Rename_management(MappingTemplate_gdb, MappingTemplate_RenameTyped_gdb, "Workspace")
  File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\management.py", line 3181, in Rename
    raise e
ExecuteError: ERROR 999999: Error executing function.
General function failure
Failed to execute (Rename).

>>>
Tags (2)
0 Kudos
6 Replies
StephenCox2
New Contributor

4 & 1/2 years later the first reply is someone having exactly the same problem...

will keep googling

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

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:

  1. Start ArcMap and open the Catalog window, or open ArcCatalog.
  2. 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.

  3. Right-click the geodatabase and click Rename.
  4. Type a new name for the geodatabase.
  5. 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.

StephenCox2
New Contributor

Thanks yeah it's 10.1. I need to do it in a script or model so I can loop

through hundreds of them.

0 Kudos
StephenCox2
New Contributor

Also good to know rename_management doesn't work on geodatabases. the help

isn't explicit about it. thanks

0 Kudos
RhettZufelt
MVP Frequent Contributor

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_

RebeccaStrauch__GISP
MVP Emeritus

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‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍