Mar-20-2019, 07:41 PM
I have a few hundreds of files in one folder and every file in the folder has 2 more corresponding files that it needs to combine with. I have done the code for finding the corresponding files and adding them into a list but I am now stuck at figuring out how to combine these files while looping through each list.
['a_b_c_111.hdf', 'b_b_c_111.hdf']
['b_c_e_112.hdf', 'c_c_e_112.hdf']
I am now stuck and finding a way to loop through this list and concatenating hdf files within each of this list.
Would appreciate some help on how best to do this. Thanks.
f = f = ['a_b_c_111.hdf', 'b_b_c_111.hdf', 'b_c_e_112.hdf','c_c_e_112.hdf']
file_to_combine = {}
for file in f:
a,b,c,d = re.split(r'[_]',file)
s = c + '_' + d
if s in file_to_combine:
file_to_combine[s].append(os.path.join(file))
else:
file_to_combine[s] =[os.path.join(file)]
for (k, v) in file_to_combine.items():
files = [','.join(v)]
for i in files:
split_files = files[0].split(",")
print (split_files) running this script will result in 2 lists but it will be more when I run through 100s of files:['a_b_c_111.hdf', 'b_b_c_111.hdf']
['b_c_e_112.hdf', 'c_c_e_112.hdf']
I am now stuck and finding a way to loop through this list and concatenating hdf files within each of this list.
Would appreciate some help on how best to do this. Thanks.
