-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCombineAndSortFiles.py
More file actions
29 lines (22 loc) · 954 Bytes
/
CombineAndSortFiles.py
File metadata and controls
29 lines (22 loc) · 954 Bytes
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
import glob
def readFile(fileType, outFile, doSortFile):
read_files = glob.glob("*." + fileType)
with open(outFile + "." + fileType, "wb") as outfile:
for f in read_files:
with open(f, "rb") as infile:
outfile.write(infile.read())
if doSortFile == True:
with open(outFile + "." + fileType, 'r') as r:
with open(outFile + "_sorted" +"." + fileType, "w") as outfile:
for line in sorted(r):
outfile.write(line)
def main():
# if len(sys.argv) > 0:
# setParams()
fileType = input("Set file type? #type 'txt' or 'csv': ")
outFile = input("Set out file name #type the file name without an extension: ")
doSortFile = input('Sort the out file lines alphabetically? #type y or n: ')
if (doSortFile.upper() == 'Y') or (doSortFile.upper() == 'YES'):
doSortFile = True
readFile(fileType, outFile, doSortFile)
main()