我在不同位置的3台服务器上运行脚本,每天晚上使用YYYY MM DD
将JPG移动到文件夹,即今天捕获的图像将在23:55移动到名为2014的文件夹,这是一个名为2014的文件夹12,以及另一个名为31的子文件夹。
但是,我想将月份设为 12月而不是 12 。
我使用的脚本是:
@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 :(得分: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%
答案 1 :(得分: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
附加到该行以禁止该目录已存在& #39;信息。这样可以节省一大堆代码......