-
Notifications
You must be signed in to change notification settings - Fork 0
/
mergeFiles.py
44 lines (29 loc) · 1.04 KB
/
mergeFiles.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
import sys
import os
# Get working directories and extension
directory = sys.argv[1]
extension = sys.argv[2]
# Gets the list of files for the directory to inspect
filesList = os.listdir(directory)
filesList.sort()
# Opens the output file
outputFileName = 'DIRECTORY_MERGE'
outputFile = open(directory + outputFileName + extension, 'a')
# Checks if
for fileName in filesList:
# Checks if the file meets the requirements
if fileName.endswith(extension):
print "[STATUS 2] Merging '" + fileName + "' with master file (path: '" + directory + "')"
outputFile.write('--' + fileName + '\n')
# Opens the file that needs to be appended to the output one
inputFile = open(directory + fileName, 'r')
# Reads the file
allLines = inputFile.readlines()
# Appends every line in the output file
for singleLine in allLines:
outputFile.write(singleLine)
outputFile.write('\n\n\n')
# Closes input file
inputFile.close()
# Closes output file
outputFile.close()