-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathfind_and_rename_and_move.py
More file actions
49 lines (39 loc) · 1.32 KB
/
Copy pathfind_and_rename_and_move.py
File metadata and controls
49 lines (39 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os
import shutil
import time
import argparse
def copy_rename(src_file_path: str, output_dir) -> str:
des_file_name = src_file_path.replace('/', '~')
des_file_path = os.path.join(output_dir, des_file_name)
shutil.copy(src_file_path, des_file_path)
def add_argument():
parser = argparse.ArgumentParser(
description="List all file paths in a folder")
parser.add_argument("-i",
"--inputDir",
help="Path to the target folder(only absolute path is accepted)",
type=str)
parser.add_argument("-o",
"--output",
help="Directory path that files will be saved", type=str)
args = parser.parse_args()
return args
def scanRecurse(baseDir):
for entry in os.scandir(baseDir):
if entry.is_file():
yield os.path.join(baseDir, entry.name)
else:
yield from scanRecurse(entry.path)
def main():
start_time = time.time()
args = add_argument()
dir_path = args.inputDir
output_dir = args.output
i = 1
for path_file in scanRecurse(dir_path):
copy_rename(path_file, output_dir)
print(i, end='\r')
i = i + 1
print("--- %s seconds ---" % (time.time() - start_time))
if __name__ == '__main__':
main()