Guest User

Untitled

a guest
Jul 17th, 2023
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. import os
  2. import mido
  3. from tqdm import tqdm
  4.  
  5. folder_path = 'LAKH-MuseNet-CC-BY-NC-SA2'
  6. output_file = 'names4.txt'
  7. max_file_size_kb = 400
  8.  
  9. with open(output_file, 'w', encoding="utf-8") as f:
  10. midi_files = []
  11. for subdir, dirs, files in os.walk(folder_path):
  12. for file in files:
  13. if file.endswith('.mid'):
  14. # f.write(filename + '\n')
  15. file_path = os.path.join(subdir, file)
  16. midi_files.append(file_path)
  17. for file_path in tqdm(midi_files, desc='writing MIDI name/path list', unit='file'):
  18. try:
  19. file_size_kb = os.path.getsize(file_path) / 1024 # Get file size in KB
  20. if file_size_kb <= max_file_size_kb:
  21. f.write(file_path + '\n')
  22. else:
  23. print(f'File is too large: {file_path}')
  24. except Exception as e:
  25. print(f'Error processing file {file_path}: {e}')
  26.  
Advertisement
Add Comment
Please, Sign In to add comment