Sign up ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am having problems with lock files while deleting and copying geodatabases for backup purposes.

print "Now backing up your Geodatabase"
distutils.dir_util.remove_tree (r"\\Msukserver\gis\geodatabase BACKUP\EVERYONE\Mining Features (MATTHEW).gdb", 0, 0) # deletes 'everyone' backup copy
distutils.dir_util.copy_tree(r"\\Msukserver\gis\geodatabase BACKUP\MATT\Mining Features (MATTHEW).gdb", r"\\Msukserver\gis\geodatabase BACKUP\EVERYONE\Mining Features (MATTHEW).gdb") # backup the last backup to 'everyone'
print "old backup copied"
distutils.dir_util.remove_tree(r"\\Msukserver\gis\geodatabase BACKUP\MATT\Mining Features (MATTHEW).gdb", 0, 0) # deletes last backup
print "old backup deleted"
distutils.dir_util.copy_tree(r"C:\GIS Home\Mining Features (MATTHEW).gdb", r"\\Msukserver\gis\geodatabase BACKUP\MATT\Mining Features (MATTHEW).gdb") # copy mining features to create new backup
print "::::::::::::::::::::::Backup Complete::::::::::::::::::::::"
raw_input("Push Return key to close...")

I am getting a 'permission denied' error on the '.lock' files. Is there a way of copying/deleting all the file except those with a .lock extension? or a way to continue/force with errors? I am aware that I am currently copying/deleting the entire directory and may need to change my code to copy/delete files only.

share|improve this question
Have you considered using arcpy.Copy_management and arcpy.Delete_managementto do this? – blah238 Oct 8 '12 at 16:32
Also if you have the geodatabase open in ArcMap, ArcCatalog, etc., you will not be able to delete it except within the application that has the lock on it. – blah238 Oct 8 '12 at 16:34

1 Answer 1

You can try omitting the ".lock" extension in order to avoid removing those files. However, I think you may have to use the cleanup function through ArcObjects to remove everything.

folder = "folder path"
for the_file in os.listdir(folder):
    if ".lock" not in the_file:
        file_path = os.path.join(folder, the_file)
            if os.path.isfile(file_path):
        except Exception, e:
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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