-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenmae.py
51 lines (29 loc) · 1.15 KB
/
renmae.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
import glob, os
global ii
def rename(dir, pattern, titlePattern,i):
for pathAndFilename in glob.iglob(os.path.join(dir, pattern)):
title, ext = os.path.splitext(os.path.basename(pathAndFilename))
os.rename(pathAndFilename,
os.path.join(dir, titlePattern % str(i).zfill(4) ))
i = i + 1
global ii
ii = i
print(i)
rename(r'/home/godfather/Documents/text-search-engine-master/input',r'*',r'doc%s',0)
for x in range(ii):
with open("input/doc" + str(x).zfill(4),'r') as infile,open("corpus/doc" + str(x).zfill(4), 'w') as outfile:
for line in infile:
if not line.strip():
continue
outfile.write(line)
infile.close()
outfile.close()
# with open("corpus/doc" + str(x).zfill(4),'w') as write_to , open('o.txt', 'r') as write_from:
# for line in write_from:
# write_to.write(line)
# write_to.close()
# write_from.close()
# with open("corpus/doc" + str(doc_id).zfill(4)) as infile, open('output.txt', 'w') as outfile:
# for line in infile:
# if not line.strip(): continue # skip the empty line
# outfile.write(line) # non-empty line. Write it to output