def _deleteFolderWin32(self, full_path): """A function like shutil.rmtree using win32api. The win32file apis must be used for this task on win32 platform because the win32 shell libs cannot handle file paths > 256 chars long. Args: full_path: Absolute path of the folder to recursively delete. """ unicode_path = '\\\\?\\%s' % full_path folder_iterator = win32file.FindFilesIterator(unicode_path + '\\*') FILE_ATTRIBUTE = 0 FILE_NAME = 8 FILE_ATTRIBUTE_DIRECTORY_VISTA = 8208 for file_info in folder_iterator: if file_info[FILE_NAME] == '.' or file_info[FILE_NAME] == '..': continue if (file_info[FILE_ATTRIBUTE] == win32file.FILE_ATTRIBUTE_DIRECTORY or file_info[FILE_ATTRIBUTE] == FILE_ATTRIBUTE_DIRECTORY_VISTA): self._deleteFolderWin32('%s\\%s' % (full_path, file_info[FILE_NAME])) continue else: win32file.DeleteFileW('%s\\%s' % (unicode_path, file_info[FILE_NAME])) del folder_iterator win32file.RemoveDirectory(unicode_path)
def delete_originals(self): import win32file for path in self.handle_map: win32file.DeleteFileW(path) self.close_handles()