Last active
February 7, 2023 11:54
-
-
Save poacosta/1f4b0185135b6038e3129a69e4981749 to your computer and use it in GitHub Desktop.
Create files by extensions 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 | |
EXTENSIONS = ['py', 'rb', 'cs', 'ex', 'js', 'go', 'rs', 'dart', 'php', 'sql'] | |
def create_files_by_extension_given_a_filename(name, directory): | |
for extension in EXTENSIONS: | |
file = f"{name}.{extension}" | |
if os.path.exists(os.path.join(directory, file)): | |
print('{0}: already exists!'.format(file)) | |
else: | |
with open(os.path.join(directory, file), 'w'): | |
pass | |
if __name__ == '__main__': | |
path = r"/<desired-path>/" | |
filename = "name_of_file" | |
create_files_by_extension_given_a_filename(filename, path) | |
print("Done!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment