Forum help document > BBCode
This code will create a single file from the .dat files in the folder
This code will create a single file from the .dat files in the folder
import glob def yield_dat_file(file_name): with open(file_name) as file_obj: next(file_obj) for line in file_obj: frame, action = line.split() file_number, _ = file_name.split('.') yield int(file_number), int(frame), action def yield_all_dat_files(): dat_file_names = glob.glob('*.dat') for file_name in sorted(dat_file_names): for dat_row in yield_dat_file(file_name): yield dat_row def create_single_dat(): with open('FINAL.dat', 'w') as file_obj: file_obj.write('MohoSwitch1\n') for file_number, frame, action in yield_all_dat_files(): file_obj.write('{} {}\n'.format(file_number + frame, action)) create_single_dat()Final.dat
MohoSwitch1 1 FV 2 L 235 AI 237 etc 565 rest 577 E