Added moving mechanism

master
Jason Zhu 2021-08-15 20:05:24 +10:00
parent 65d20e9701
commit a498e0d502
1 changed files with 13 additions and 7 deletions

View File

@ -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)