2011-10-04 4 views
1

요일을 기준으로 폴더에있는 파일로 FTP 업로드를 자동화하려고합니다. 오늘은 화요일이므로 스크립트를 // server/folder/Tuesday 폴더로 이동하여 해당 폴더에 파일을 업로드하고 싶습니다.Python - 디렉토리를 요일을 기준으로 폴더로 변경합니다.

나는이 있습니다

os.chdir("//MTR-SRV/Creative/CHARGER/Monitor/Out") 
cwd = os.getcwd() 

print "1", cwd 

을하지만 바로 그 날 폴더 전에 폴더에 저를 가져옵니다. // MTR-SRV/Creative/Charger/Monitor/Out/Tuesday (오늘 날짜는 오늘 무엇이든)

아이디어가 필요하십니까?

답변

7

당신은 같은 요일을 얻을 수 있습니다 :

import time 
dayofweek = time.strftime('%A') 
os.chdir("//MTR-SRV/Creative/CHARGER/Monitor/Out/" + dayofweek) 
+1

또는,보다 일반적인하려면 : 귀하의 경우

>>> import time >>> time.strftime('%A') 'Tuesday' 

을,이 트릭을 할 에게서는 'os.path.join()'을 사용하십시오. 또한'datetime.date.today()'뿐만 아니라'now()'도 작동합니다. – agf

+3

또는 짧게 :'time.strftime ('% A') ' – JBernardo

+0

브릴리언트. 고맙습니다! –

1
import datetime 

dayname = datetime.datetime.now().strftime('%A') 
os.chdir("//MTR-SRV/Creative/CHARGER/Monitor/Out/%s" % dayname) 
cwd = os.getcwd() 

print "1", cwd 
관련 문제