Skip to content

Instantly share code, notes, and snippets.

@zcaceres
Last active November 1, 2018 23:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zcaceres/0cf04f5f6e61d8c37f77483ea5cff03e to your computer and use it in GitHub Desktop.
Save zcaceres/0cf04f5f6e61d8c37f77483ea5cff03e to your computer and use it in GitHub Desktop.
Composer Deep Learning #2
#!/usr/bin/env python3
from pathlib import Path
from sys import argv
# Converts all files in specified directory to format [foldername]_[filenumber]
def rename_files(folder_path, folder_name):
files = [file for file in folder_path.iterdir() if file.is_file() and ("mid" in file.name)]
for (x, file) in enumerate(files):
print('Renaming', file)
file.rename(f'{folder_path}/{folder_name}_{x}.mid')
print('Done')
def recursive_rename(dir_path):
folders = [folder for folder in dir_path.iterdir() if folder.is_dir()]
for folder in folders:
print('Renaming:', folder.name)
rename_files(root_path/f'{folder.name}', folder.name)
if (len(argv) < 2):
raise Exception('Please specify a path')
path = Path(argv[1])
recursive_rename(root_path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment