Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import mido
- from tqdm import tqdm
- folder_path = 'LAKH-MuseNet-CC-BY-NC-SA2'
- output_file = 'names4.txt'
- max_file_size_kb = 400
- with open(output_file, 'w', encoding="utf-8") as f:
- midi_files = []
- for subdir, dirs, files in os.walk(folder_path):
- for file in files:
- if file.endswith('.mid'):
- # f.write(filename + '\n')
- file_path = os.path.join(subdir, file)
- midi_files.append(file_path)
- for file_path in tqdm(midi_files, desc='writing MIDI name/path list', unit='file'):
- try:
- file_size_kb = os.path.getsize(file_path) / 1024 # Get file size in KB
- if file_size_kb <= max_file_size_kb:
- f.write(file_path + '\n')
- else:
- print(f'File is too large: {file_path}')
- except Exception as e:
- print(f'Error processing file {file_path}: {e}')
Advertisement
Add Comment
Please, Sign In to add comment