2014-12-31 74 views
0

我有一個腳本在不同位置的3臺服務器上運行,每天晚上使用YYYY MM DD將JPG移動到一個文件夾,即今天捕獲的圖像將在23:55移動到名爲2014的文件夾,稱爲12的子文件夾,子文件夾名爲31.如何從月份得到月份的簡稱?

但是,我想將月份設置爲Dec而不是。

我使用的腳本是:

@ECHO OFF 
CLS 

e: 
cd \webcam\webadminpan 

ECHO Checking For any JPG Files 
DIR /b *.jpg > NUL 2>&1 
IF ERRORLEVEL 1 GOTO NoFilesFound 
ECHO Found Files To Move 

SET thisyear=%date:~6,4% 
echo I am this year : %thisyear% 
SET thismonth=%date:~3,2% 
echo I am this month : %thismonth% 
SET thisday=%date:~0,2% 
echo I am this day : %thisday% 

:CheckYearCreate 
ECHO Checking to see if year directory %thisyear% exists 
DIR /b "%thisyear%"> NUL 2>&1 
IF ERRORLEVEL 1 GOTO CreateYear 
ECHO Directory %thisyear% must already be present 

:CheckMonthCreate 
ECHO Checking to see if month directory %thismonth% exists 
DIR /b "%thisyear%\%thismonth%"> NUL 2>&1 
IF ERRORLEVEL 1 GOTO CreateMonth 
ECHO Directory %thisyear%/%thismonth% must already be present 

:CheckDayCreate 
ECHO Checking to see if day directory %thisday% exists 
DIR /b "%thisyear%\%thismonth%\%thisday%"> NUL 2>&1 
IF ERRORLEVEL 1 GOTO CreateDay 
ECHO Directory %thisyear%/%thismonth%/%thisday% must already be present 

:MoveJPGFiles 
ECHO Moving JPG Files To "%thisyear%/%thismonth%/%thisday%" 
MOVE *.jpg "%thisyear%\%thismonth%\%thisday%" 
GOTO TheEnd 


:CreateYear 
ECHO Making Year %thisyear% Directory 
MKDIR "e:\webcam\webadminpan\%thisyear%" 
GOTO CheckYearCreate 

:CreateMonth 
ECHO Making Month %thismonth% Directory 
MKDIR "e:\webcam\webadminpan\%thisyear%\%thismonth%" 
GOTO CheckMonthCreate 

:CreateDay 
ECHO Making Day %thisday% Directory 
MKDIR "e:\webcam\webadminpan\%thisyear%\%thismonth%\%thisday%" 
GOTO CheckDayCreate 

:NoFilesFound 
ECHO Nothing to Move 

:TheEnd 
ECHO Finished 

Exit /b 0 

任何人都可以對我怎麼能做到這一點,並得到thismonth組與短縮寫,而不是數量的建議?

回答

0

試試這個thismonth初始化後:

:: assuming that thismonth is already set by your script. 
set thismonth=09 

:: clears the leading zeroes 
cmd /c exit /b %thismonth% 
set c_month=%errorlevel% 

:: sets month as a word but not as a digits 
for /f "tokens=%c_month%" %%a in ("Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec") do set "w_month=%%a" 

:: month is set as a word 
echo %w_month% 
0
FOR %%a IN ("01 Jan" "02 Feb" "06 Jun" "07 Jul") DO FOR /f "tokens=1,2" %%b IN (%%a) DO IF %month%==%%b SET "month=%%c" 

假設你month具有領先的零 - 刪除前導零,如果事實並非如此。該代碼用文本替換month中的數字值。

順便說一句 - 您可以MKDIR一個目錄(或MD - 它是一個同義詞),並簡單地追加2>nul行以抑制'目錄已存在'消息。這將爲您節省一堆代碼...