-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrec2csv.py
More file actions
40 lines (29 loc) · 988 Bytes
/
rec2csv.py
File metadata and controls
40 lines (29 loc) · 988 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
30
31
32
33
34
35
36
37
38
39
40
import os
dirfiles = os.listdir()
recs = [x for x in dirfiles if x.endswith(".rec")]
files = []
### Løb igennem REC-filer.
for rec in recs:
filename = rec.split('.')[0]
files.append(filename + ' csv.csv')
### Åbn .rec- og lav/åbn .csv-fil:
fr = open(filename + '.rec',"r")
fw = open(filename + ' csv.csv',"w")
### Læs .rec-fil:
lines = fr.readlines()[2:]
rows = [line for line in lines]
for line in rows:
### Trim data:
row = line.replace(" [","_[").replace('%','').split()
# print(row)
### Skriv trimmet data til csv-fil:
for i in row: fw.write(i.replace('_',' ') + ';')
fw.write('\n')
### Luk filer:
fr.close()
fw.close()
### Flere REC-filer?
if len(recs) > 1:
print("- - - - -\nOBS!\nDer er flere REC-filer.\nDer er lavet en CSV-fil for hver REC-fil. Se herunder:\n")
for f in files: print("\""+f+"\"")
print("- - - - -")