-
Notifications
You must be signed in to change notification settings - Fork 0
/
fileMergerUtil.py
42 lines (34 loc) · 1.29 KB
/
fileMergerUtil.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
import glob
import shutil
import os
# set to the file extension of "to-be-merged" files
ext = '.csv'
# set to your working directory
dir_path = 'C:\\Users\\NUCER\\Documents\\git\\WiCoSens\\MLDataClassifiers\\datarecording_discrete\\rgb\\'
#dir_path = 'C:\\Users\\NUCER\\Documents\\git\\WiCoSens\\MLDataLabeler\\datarecording\\'
dir_path = "C:\\Users\\NUCER\\Documents\\git\\WiCoSens\\MLDataClassifiers\\datarecording_discrete\\color_concept\\"
# set to the name of your output file
outfilename = dir_path + 'train.csv'
'''
with open(outfilename, 'w') as outfile:
for filename in glob.glob(dir_path + '*.csv'):
if filename == outfilename:
# don't want to copy the output into the output
continue
with open(filename, 'r') as readfile:
shutil.copyfileobj(readfile, outfile)
#OR
with open(dir_path + outfilename, 'w') as outfile:
for filename in glob.glob(dir_path + '*.csv'):
with open(filename) as infile:
for line in infile:
outfile.write(line)
'''
with open(outfilename, 'a') as singleFile:
for csv in glob.glob(dir_path +'train_*.csv'):
if csv == outfilename:
pass
else:
for line in open(csv, 'r'):
singleFile.write(line)
singleFile.write('\n')