def test_valid_extension_organization(self): file_list = ['file1.docx', 'file2.exe.exe', 'file3.docx.exe', 'file5.sdx', 'some.power'] organizer = Organizer('C:') organizer.file_list = file_list files_by_extensions = organizer.organize_by_extension() self.assertCountEqual(files_by_extensions['exe'], ['file2.exe.exe', 'file3.docx.exe']) self.assertCountEqual(files_by_extensions['docx'], ['file1.docx']) self.assertCountEqual(files_by_extensions['power'], ['some.power'])
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)