-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcopy_alternate_out.py
More file actions
executable file
·86 lines (65 loc) · 2.21 KB
/
copy_alternate_out.py
File metadata and controls
executable file
·86 lines (65 loc) · 2.21 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/usr/bin/env python3
#encoding=utf-8
from os import listdir, remove, rename
from os.path import join, exists, splitext
# to copy/move file.
import shutil
def contain_alt(file_path):
ret = False
input_file = open(file_path, 'r')
left_part_alt = 'AltUni2: '
left_part_alt_length = len(left_part_alt)
left_part_SplineSet = 'SplineSet'
left_part_SplineSet_length = len(left_part_SplineSet)
x_line = input_file.readline()
for x_line in input_file:
#while x_line:
#print(x_line)
if left_part_alt == x_line[:left_part_alt_length]:
ret = True
break
if left_part_SplineSet == x_line[:left_part_SplineSet_length]:
break
#x_line = input_file.readline()
return ret
def scan_files(ff_folder, target_folder):
files = listdir(ff_folder)
file_count = 0
copy_count = 0
for f in files:
file_count += 1
# must match extension only, exclude ".extension.tmp" file.
extension = splitext(f)
#print("extension:", extension[1])
#break
if extension[1] == '.glyph':
# skip hidden files.
if f[:1] == ".":
continue
if f == "nonmarkingreturn.glyph":
continue
source_path = join(ff_folder,f)
alt_check = contain_alt(source_path)
if alt_check:
#print("match filepath:", source_path)
target_path = join(target_folder,f)
shutil.copy(source_path,target_path)
copy_count += 1
print("file_count:", file_count)
print("copy_count:", copy_count)
if __name__ == '__main__':
import sys
argument_count = 3
clean_max_count = 99999
if len(sys.argv)==argument_count:
source_ff = sys.argv[1]
target_folder = sys.argv[2]
if len(source_ff) > 0:
if not exists(source_ff):
if not ".sfdir" in source_ff:
source_ff += ".sfdir"
if exists(source_ff):
scan_files(source_ff,target_folder)
else:
print("Argument must be: %d" % (argument_count -1))
print("Ex:%s ff_folder target_folder" % (sys.argv[0]))