forked from tdwojak/Python2017
31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
|
import glob
|
||
|
import pathlib as p
|
||
|
|
||
|
|
||
|
# set the path to directory
|
||
|
my_path = 'C:/Users/**/*.bleu'
|
||
|
new_dict = {}
|
||
|
# match files in given directory
|
||
|
for name in glob.glob(my_path, recursive=True):
|
||
|
# for each file in directory set it's path and open the file
|
||
|
path_to_file = p.Path(name)
|
||
|
with path_to_file.open() as f:
|
||
|
# read 1st line in each file
|
||
|
line = f.readline()
|
||
|
# split this line using ',' as separator
|
||
|
line_splitted = line.split(',')
|
||
|
# in this case BLUE = YY.YY is the first element of the list,
|
||
|
# now we have to split it by ' ' and add it to dictionary
|
||
|
# which key will be the file name and value will be that value
|
||
|
for i, j in enumerate(line_splitted):
|
||
|
if i == 0:
|
||
|
blue_splitted = j.split(' ')
|
||
|
second_element = float(blue_splitted[2])
|
||
|
# in that case searched value is on 3rd position (2nd list element)
|
||
|
new_dict.update({path_to_file: second_element})
|
||
|
print(new_dict)
|
||
|
# find max key (path) searching by values
|
||
|
maximum = max(new_dict, key=new_dict.get)
|
||
|
print(maximum)
|
||
|
|