Created
April 14, 2020 17:45
-
-
Save robertlugg/7afdf980460280c248c95e325e942279 to your computer and use it in GitHub Desktop.
Make directory. Write file.
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
import os | |
# User entry of folder name. Make it. | |
folder = input("Folder name:") | |
try: | |
os.makedirs(folder) | |
except: | |
pass | |
# User entry of file base. Build full path. | |
file_prefix = input("File prefix:") | |
filename = file_prefix + os.extsep + 'txt' | |
filepathname = os.path.join(folder, filename) | |
print(f'Writing to:{filepathname}') | |
# Write to a file. | |
with open(filepathname, 'w') as file: | |
file.write("Hey, it's working") | |
# Confirm file has been created. | |
os.system(f'dir {folder}') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment