-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetBoreholeName.py
38 lines (35 loc) · 964 Bytes
/
getBoreholeName.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
# get the boreholeNames
import os, fnmatch
from collections import OrderedDict
def getBoreholeName(fileDir):
"""
:in fileDir: directory to the folder
:out boreholeNames: ordered boreholeNames in a list
['WO03109',
'WO03118',
'WO05117',
'WO07111',
'WO07116',
'WO10112',
'WO10115',
'WO34113',
'WO34114',
'WO34118',
'WO41112',
'WO41115',
'WO41117',
'WO45116',
'WO48110',
'WO55109']
"""
listOfFiles = os.listdir(fileDir)
pattern = "*.mat"
matFile = []
for entry in listOfFiles:
if fnmatch.fnmatch(entry, pattern):
matFile.append(entry.split('_')[0])
# '624reshape.mat' was deleted that's why the index is [1:]
# set to delete the duplicates(without), but results are not in order
#boreholeNames = list(set(matFile[1:]))
boreholeNames = list(OrderedDict.fromkeys(matFile[1:]).keys())
return boreholeNames