Last active
January 16, 2023 03:31
-
-
Save poacosta/f9a19b7b51f692421dec856e1050422b to your computer and use it in GitHub Desktop.
Create directories by file names given a path using Python
This file contains hidden or 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
| import os | |
| def create_dirs_by_filenames(filenames, parent_dir): | |
| mode = 0o777 | |
| for directory in filenames: | |
| os.mkdir(os.path.join(parent_dir, directory), mode) | |
| def get_filenames(path): | |
| dir_list = [os.path.splitext(x)[0].replace(':', '-') for x in os.listdir(path)] | |
| return sorted(set(dir_list)) | |
| if __name__ == '__main__': | |
| path = "/<desired-path>/" | |
| create_dirs_by_filenames(get_filenames(path), path) | |
| print("Done!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment