Python - change directory to a folder based on what day of the week it is
I'm trying to automate an ftp upload with files that are in folders based on the day of the week. Since today is Tuesday I would like to have the script go to the //server/folder/Tuesday folder, and upload开发者_StackOverflow中文版 the files in that folder.
I have this:
os.chdir("//MTR-SRV/Creative/CHARGER/Monitor/Out")
cwd = os.getcwd()
print "1", cwd
but that just gets me to the folder right before the day folder. I need it to get to //MTR-SRV/Creative/Charger/Monitor/Out/Tuesday (or whatever today's date is)
any ideas?
You can get the day of the week like this:
>>> import time
>>> time.strftime('%A')
'Tuesday'
In your case, this ought to do the trick:
import time
dayofweek = time.strftime('%A')
os.chdir("//MTR-SRV/Creative/CHARGER/Monitor/Out/" + dayofweek)
import datetime
dayname = datetime.datetime.now().strftime('%A')
os.chdir("//MTR-SRV/Creative/CHARGER/Monitor/Out/%s" % dayname)
cwd = os.getcwd()
print "1", cwd
精彩评论