0

I made a tool in ArcGIS Python Add-Ins for my colleagues and right now wrote an update in main script. It would be easy to tell everyone to delete old add-in and install new one, but recently found the path to the initial script of a tool which is C:\Users\%username%\AppData\Local\ESRI\Desktop10.2\AssemblyCache\folder with a long name\file.py. I tried to make a script that could make a backup of file.py to file_backup.py, take a new file and paste it in found folder. Script works well, the new file with new updates is there, but when I launch ArcMap there are no any changes. I can see that the file is the same that I used before.

Is it technically possible to perform this operation using the change of files?

The script is:

import os
import shutil
loc = os.environ.get('LOCALAPPDATA')
filename = 'Pointer_addin.py'

for x in os.walk(loc): 
    if filename in str(x) :
        print os.path.join(x[0],filename) 
        path = x[0]
        filepath = os.path.join(x[0],filename) 


os.rename(filepath,filepath.rstrip('.py') + '_backup.py')
newp=r'D:\Pointer\Install\Pointer_addin.py'
shutil.copy(newp,path)
1

You have not used os.walk properly. It hasnt correctly identified the old file. Try the below. This should identify the filename in the location, create a new file name, rename the original file, and copy the new addin to the location.

import os
import shutil
loc = os.environ.get('LOCALAPPDATA')

for root, dirs, files in os.walk(loc): 
    for file in files:    
        if file.endswith('Pointer_addin.py') :
            filepath = os.path.join(root, file) 
            print filepath

newfilename = filepath.replace(".py", "_backup.py")
os.rename(filepath, newfilename)
newp = r'D:\Pointer\Install\Pointer_addin.py'
shutil.copy(newp, filepath)
  • well I actually found that my script works and file goes to the right directory. The problem is based on arcmap's resources - an updated was again returned to it's past condition. I tried to change permission to 'Read only' and it worked!! But ONLY in ArcGIS 10.2. I wanted to did the same in 10.5 and in this case it didn't worked... – Pavel Pereverzev Sep 27 '17 at 11:06

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.