开发者

Python - change directory to a folder based on what day of the week it is

开发者 https://www.devze.com 2023-04-10 09:47 出处:网络
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 u

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
0

精彩评论

暂无评论...
验证码 换一张
取 消