Last active
November 1, 2018 23:13
-
-
Save zcaceres/0cf04f5f6e61d8c37f77483ea5cff03e to your computer and use it in GitHub Desktop.
Composer Deep Learning #2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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