-
Notifications
You must be signed in to change notification settings - Fork 0
/
combine.py
64 lines (48 loc) · 1.53 KB
/
combine.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from shutil import copy
from sys import argv
from pathlib import Path
import traceback
fileNameTemplate = "{0:04}"
def CombineFolder(inputPath: Path, outputPath: Path, index):
files: list[Path] = [x for x in inputPath.iterdir()]
files.sort()
for file in files:
fileExt = file.suffix.rsplit(".", 1)[-1]
newFileName = fileNameTemplate.format(index) + f".{fileExt}"
newFilePath = outputPath.joinpath(newFileName)
copy(file, newFilePath)
print(f"\tMove : {file}")
print(f"\t to : {newFilePath}")
index += 1
return index
def CombineFolders(inputPaths, output):
currentItem = 1
for dir in inputPaths:
print(f"Iterate : {dir}")
currentItem = CombineFolder(dir, output, currentItem)
def main():
if len(argv) <= 1:
print("Please take parameters as input")
exit(0)
inputPaths = [Path(x) for x in argv[1:]]
inputPaths.sort()
print("Here are folder list :")
for path in inputPaths:
print(f"\t{path}")
basePath = Path(inputPaths[0]).parent
print(f"BasePath : {basePath}")
print("\nPlease input output folder name")
outputName = input()
destPath = basePath.joinpath(outputName)
if destPath.exists():
print(f"Output path is exists, will remove it, {destPath}")
destPath.rmdir()
destPath.mkdir()
CombineFolders(inputPaths, destPath)
print("Work Done!")
if __name__ == "__main__":
try:
main()
except Exception:
print(traceback.format_exc())
input()