-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathformatting.py
More file actions
56 lines (46 loc) · 1.52 KB
/
Copy pathformatting.py
File metadata and controls
56 lines (46 loc) · 1.52 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
import argparse
import os
'''
Delete all gaps and convert names.
'''
parser = argparse.ArgumentParser()
parser.add_argument("-F", help='File name')
parser.add_argument("-S", help='Substitute character')
parser.add_argument("-R", help='Recursive formatting - all files in folder will be formatted, use instead of -F flag')
args = parser.parse_args()
def Iteration(filename, new_character):
num_lines = sum(1 for line in open(f'{filename}.txt'))
nowy = open(f'{filename.split("/")[0]}/format/{filename.split("/")[-1]}_f.txt', 'w')
with open(f'{filename}.txt') as filename:
for i in range(num_lines):
linia_pliku = filename.readline()
temp = ''
if '>' in linia_pliku:
for i1 in linia_pliku:
if i1 == '/' or i1 == '-':
temp += new_character
else:
temp += i1
else:
for i1 in linia_pliku:
if i1 != '-':
temp += i1
nowy.write(temp)
nowy.close()
new_character = '_'
if args.S:
new_character = str(args.S)
if args.R:
listaplikow = os.listdir(args.R)
for i in listaplikow:
if '_f.txt' not in i:
if i != 'format':
Iteration(f'{args.R}/{i.split(".")[0]}', new_character)
elif args.F:
filename = args.F
if '.' in filename:
filename = filename.split(".")[0]
Iteration(filename, new_character)
else:
print('No file or folder')
exit()