Hi, I've this backup script that having some problems. Please some one suggest what is that I'm missing in it. This backup script deletes the previous backups and then create a new backup by simply renaming the original folder to backup folder and creates a new folder.
The folder contains many files and folders and many .svn (i.e. hidden and readonly files and directories) Well things seems to be done correctly but at times while renaming the folder to backup I get this error WindowsError: [Error 5] Access is denied Here is my code: The thread class that removes the hidden and readonly permission from files and folders. Then using shutil.rmtree to delete the files import threading import win32con import win32api import win32file import sys import shutil sys.setrecursionlimit(5000) class delDirTreeThread(threading.Thread): def __init__(self, path): self.path = path threading.Thread.__init__(self) def run(self): self.delRecursive(self.path) shutil.rmtree(self.path) def delRecursive(self, path): for file in os.listdir(path): file_or_dir = os.path.join(path,file) if os.path.isdir(file_or_dir): print file_or_dir print "file_or_dir: %s - %d" %(file_or_dir, win32file.GetFileAttributesW(file_or_dir)) if win32file.GetFileAttributesW(file_or_dir) != win32con.FILE_ATTRIBUTE_NORMAL: win32file.SetFileAttributesW(file_or_dir, win32con.FILE_ATTRIBUTE_NORMAL) if os.listdir(file_or_dir) != []: self.delRecursive(file_or_dir) #it's a directory recursive call to function again else: print file_or_dir print "ELSE - file_or_dir: %s - %d" %(file_or_dir, win32file.GetFileAttributesW(file_or_dir)) if win32file.GetFileAttributesW(file_or_dir) != win32con.FILE_ATTRIBUTE_NORMAL: win32file.SetFileAttributesW(file_or_dir, win32con.FILE_ATTRIBUTE_NORMAL) #os.remove(file_or_dir) #it's a file, delete it >From some part in application I call this threading class as: delTree = delDirTreeThread(subdir) delTree.start() delTree.join() subdir is the absolute path to the directory tree for which I want to create a new backup and delete the older ones. The very reason I did this inside a thread is because I want application to wait until the backup created (making sure that the older ones are deleted and new one created) Can some one help in this? Regards, Rajat
-- http://mail.python.org/mailman/listinfo/python-list