From a498e0d50233207b095acffc92e6cf75b954ba21 Mon Sep 17 00:00:00 2001 From: JasonHomeWorkstationUbuntu Date: Sun, 15 Aug 2021 20:05:24 +1000 Subject: [PATCH] Added moving mechanism --- mv_unique_files.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/mv_unique_files.py b/mv_unique_files.py index 6ea8f86..a401704 100644 --- a/mv_unique_files.py +++ b/mv_unique_files.py @@ -69,7 +69,8 @@ if __name__ == "__main__": parser.add_argument('--move', type=str, - help='Confirm whether to move all files with NumberOfLinks as 1 from source directory to target directory') + help='Confirm whether to move all files with NumberOfLinks as 1 from source directory to target directory', + choices=['False','True']) args = parser.parse_args() min_file_size = 50 @@ -78,12 +79,12 @@ if __name__ == "__main__": if args.size: min_file_size = args.size - paths = find_all_files(pathlib.Path(path_library)) + paths_library = find_all_files(pathlib.Path(path_library)) if args.csv == "True": csv_path = "result.csv" df_csv = pd.DataFrame(columns=['FileName', 'Path', 'inode', 'NumberOfLinks', 'CheckSum']) - for x in paths: + for x in paths_library: if x.lstat().st_size > min_file_size * 1024 * 1024: print(str(datetime.now()) + " : " + str(x)) new_row = {'FileName': x.name, @@ -103,10 +104,15 @@ if __name__ == "__main__": csv_path = args.csv_path df_csv.to_csv(csv_path,index_label='Index') else: - for x in paths: + for x in paths_library: print(str(x)) view_unqiue_files(x, min_file_size) -# dst_path = pathlib.Path(os.path.join(path_inventory,x.name)) -# print("Its new path: " + str(dst_path)) -# x.link_to(dst_path) + if args.move == "True": + target_dir = pathlib.Path(path_inventory) + for x in paths_library: + if x.lstat().st_size > min_file_size * 1024 * 1024: + print(str(datetime.now()) + " : " + str(x)) + new_path = pathlib.Path(target_dir, x.name).resolve() + print("New path: " + str(new_path)) + x.rename(new_path) \ No newline at end of file