I have a function where I am trying to rename a geodatabase, both os.rename and arcpy.Rename_management() work in the Python window but not in the Script when run as a tool through ArcCatalog.

Traceback (most recent call last):
  File "C:\PecosFieldTools\ProTools_v1.2\PhaseDeliverables\phase.py", line 562, in <module>
    arcpy.Rename_management(in_data=newGdb, out_data=phaseGdb, data_type="Workspace")
  File "c:\program files (x86)\arcgis\desktop10.6\arcpy\arcpy\management.py", line 4528, in Rename
    raise e
ExecuteError: ERROR 999999: Error executing function.
Failed to execute (Rename).

Failed to execute (Phase)

I think this may be a permission issue but I am admin running this on my own machine. When I wrap in try and except I get these error

[Errno 13] Permission denied: u'C:\\\\Projects\\\\PhaseMasters\\\\HasData\\\\1810227C\\\\Master\\\\PHASE_DELIVERABLES\\\\DB13635_AF2136641_AP_00_X04.gdb\\\\EQ_AIR_COOLED_EXCHANGER_POLY.LAPTOP-3B9ORV48.16500.16420.sr.lock'")

But when I open the file geodatabase I do not see any locks and I am deleting all my cursors. Is there a way to await the locks to be removed with Python?

enter image description here Here is where I am running the tool from.

  • 1
    If you use the Catalog window within ArcMap, then you shouldn't have lock issues, but if you run ArcCatalog and anything else, then there will be conflicts. – Vince Feb 22 at 14:31
  • That is what I mean, running the code from the catalog pane of ArcMap the tool fails but the code runs when pasted into the python Window. I turned off the background processing and no change. I don't know enough about what the python script tool does that would cause the code to work in the window but not in a tool? – Gary Lester Feb 22 at 18:14
  • 1
    I stopped using ArcCatalog when the Catalog window was added to ArcMap, so I wouldn't have lock issues. It doesn't seem counter-intuitive that you can't change the directory name on a Windows volume while that directory is open in another process. – Vince Feb 22 at 18:33
  • I am running the tool from inside arcmap. I am not sure why the directory would be in use by another process so I don't understand. – Gary Lester Feb 22 at 19:18
  • If you quit out of arcmap completely, can you rename the fgdb folder successfully? – Kirk Kuykendall Feb 22 at 21:40

I used arcpy.Compact_management before copying and renaming the geodatabase, tool now works.

copyDict = {filePath1:filePath2,filePath3:filePath4}
for k,v in copyDict.iteritems():
    arcpy.AddMessage("Copy Success")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.