2

Is there a method in ArcPy that will rename the MXD you currently have open? I don't want to use mxd.saveACopy("newFileName") as it will just save a COPY with a new name, not rename the current MXD.

Basically I want a method that will replicate the File > Save As > "newFileName.mxd" process.

os.rename() wont work, as the document is currently open.

Is this just a simple case of can't be done with ArcPy, use ArcObjects?

  • I'm voting to close this question as off-topic because this is an operating system rather than spatial software limitation. – PolyGeo Oct 26 '18 at 9:41
-1

As commented by @MichaelStimson:

Unfortunately due to file access (the MXD is open) you cannot rename it by any method. In order to perform a rename you need to close the file... this is an operating system limitation not an arcpy or python limitation. As a workaround you can save a copy then delete the original.

[and when asked about ArcObjects instead of ArcPy/Python]

No, the operating system will not let you. When you open a file (in this case MXD) the application (ArcMap) has locks placed on the file by the underlying operating system which should be read lock; what would happen if you opened a document and tried to rename it in explorer? You get error 32 from the operating system. When you 'save a copy' ArcMap doesn't switch to the new MXD, you need to do that yourself; each instance of ArcMap can only have one MXD open so the old one is closed (locks removed) which can then be deleted if you wish.

| improve this answer | |

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