-
Notifications
You must be signed in to change notification settings - Fork 0
/
file_help.py
39 lines (30 loc) · 985 Bytes
/
file_help.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
from os import listdir, mkdir, rename
from os.path import isfile, join
def get_all_files_and_clear():
"""delete all #sig# from file lines
"""
mypath = 'dataset/with/'
files = [f for f in listdir(mypath) if isfile(join(mypath, f))]
for file in files:
with open(mypath + file, "r+") as f:
lines = [line.replace("#sig#", '') for line in f.readlines()]
f.seek(0)
f.truncate()
f.writelines(lines)
def get_all_files_and_rename():
mypath = 'dataset/without/'
files = [f for f in listdir(mypath) if isfile(join(mypath, f))]
files.sort()
try:
mkdir(mypath + "tmp")
except Exception as e:
print('tmp already exist')
for i, file in enumerate(files):
new_name = mypath + "tmp/" + str(i) + "_sender"
print(new_name)
rename(mypath + file, new_name)
print(files)
def main():
get_all_files_and_clear()
if __name__ == '__main__':
main()