Skip to content

Instantly share code, notes, and snippets.

@robertlugg
Created April 14, 2020 17:45
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 robertlugg/7afdf980460280c248c95e325e942279 to your computer and use it in GitHub Desktop.
Save robertlugg/7afdf980460280c248c95e325e942279 to your computer and use it in GitHub Desktop.
Make directory. Write file.
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