I am trying to run this script so that it creates a .txt file based on the date.
#Importing libraries
import os
import sys
#Selecting time and methods
from time import gmtime, strftime
from datetime import datetime
#Fortmatting date & printing it
date = datetime.now().strftime("%Y_%m_%d-%I:%M_%p")
#Creating the name of the file, plus the date we created above
newFile = ("Summary_" + date) + '.txt'
#Creating the filepath where we want to save this file
filepath = os.path.join('C:\\Users\\myUser\\Desktop\\myFolder', newFile)
#If the path doesn't exist
if not os.path.exists('C:\\Users\\myUser\\Desktop\\myFolder'):
os.makedirs('C:\\Users\\MyUser\\Desktop\\myFolder')
f = open(filepath, "w")
Everything works, however, the file gets created as a File and not a .txt file. I am not sure if I am not concatenating the strings correctly, or if there is an additional step I need to take.
I noticed that if I type anything after the date string, it doesn't get added to the end of the file.
If I type the string manually like this, then it works just fine:
filepath = os.path.join('C:\\Users\\myUser\\Desktop\\myFolder', "Summary_DateGoesHere.txt")
Am I missing something in my script? I appreciate the assistance.