-
Notifications
You must be signed in to change notification settings - Fork 3
/
jointext.py
executable file
·27 lines (22 loc) · 869 Bytes
/
jointext.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
#!/usr/bin/python3
# program to join the contents of a directory into a single file
# for Nepali ngram model
# http://virtualanup.com/nepali-ngram-models/
import os, os.path
def makesinglefile(directory,filename):
'''
Function to read all the files in a directory
and add the contents of all the files in the directory
to a single file'''
outputfile = open(filename,"w")
for root, _, files in os.walk(directory):
for f in files:
fullpath = os.path.join(root, f)
print("Processing ",fullpath)
#open the file and read the contents
content = open(fullpath).read()
content = ' '.join(content.split())
outputfile.write(content)
outputfile.write('\n')
makesinglefile('nagariknewsoutput','nagariksingle')
makesinglefile('setopatioutput','setopatisingle')