def reorganize(self, type_of_reorganization): """ Reorganizes the directory by copying its files to their respective destinations determined by the organization type. Creates a docx report with information about the copied files """ organizer = Organizer(self.source_folder_path) organization = defaultdict(list) if type_of_reorganization == 'extension': organization = organizer.organize_by_extension() if type_of_reorganization == 'type': organization = organizer.organize_by_type() if type_of_reorganization == 'content': organization = organizer.organize_by_content(self.match_strings) # create folder named as the type of organization (extension,content..) type_folder = self.target_folder_path + "\\" + type_of_reorganization if os.path.exists(type_folder) is False: os.mkdir(type_folder) self.create_new_dirs(organization, type_folder) # create report doc_handler = DocumentHandler() # a log dictionary, holding the copied filenames and their destination log = {} for folder_name in organization: self.copy_files(organization[folder_name], type_folder + "\\" + folder_name) for file in organization[folder_name]: destination = type_folder + "\\" + folder_name log[file] = destination report = doc_handler.create_report(self.target_folder_path, log)