在TotalCmd軟體中,調用如下 python 指令碼,可在當前檔案夾下建立形如"YYYY_MM_DD"的目錄。# -*- coding: utf-8 -*-
#yankchina@gmail.com
#MakeDateFolder.py
#在輸入路徑處建立一個以當前日期命名的檔案夾
def GetDateString():
from datetime import date
todayStr = date.today().strftime("%Y_%m_%d")
return todayStr
def MakeDateFolder( inFolderName ):
import os
if os.path.isdir( inFolderName ):
newFolderName = inFolderName + '\\\\' + GetDateString()
print(newFolderName)
if os.path.isdir( newFolderName ):
print(newFolderName," Exists already ")
else:
os.mkdir( newFolderName )
print(newFolderName," Create OK ")
else:
print(inFolderName," not exists, script stop ")
#debug
#MakeDateFolder("F:\\\\temp")
#MakeDateFolder("F:\\\\temp\\\\yank")
#-----------------------------------------------------------------
#接受輸入,調用建立函數
def inputMain():
import sys
if len(sys.argv)>=2:
currentDir = sys.argv[1]
else:
print("Please Input Folder Name: ")
currentDir = raw_input()
MakeDateFolder(currentDir)
print("Any Key To Return")
currentDir = raw_input()
if __name__ == "__main__":
inputMain()
然後在TotalCmd中建立一個新的開始菜單操作,Command 就是 該Python檔案,Parameters 是 %p,Start Path 是 . 。這樣就可以在TotalCmd中運行該指令碼,會在TC的目前的目錄下建立形如(YYYY_MM_DD)的目錄。