我想修改以下命令,以便从文件名中填充日期变量。
示例:020299-INF-A-0922015.JPG应该使年变量具有值2015.
命令:
ruby -v
答案 0 :(得分:0)
我已经失去了做愚蠢的Windows BATCH生活的意愿,但你可以这样做:
@echo off
REM Start with your filename
set f=020299-INF-A-0922015.JPG
REM Parse out last chunk, splitting on dashes and dots selecting 4th field
for /f "tokens=4 delims=-." %%a in ("%f%") do set chunk=%%a
echo.%chunk%
REM Take last 4 digits of "chunk" as year
set year=%chunk:~-4%
echo.%year%
REM Take first 2 characters of "chunk" as month
set month=%chunk:~0,2%
echo.%month%
REM Strip year off "chunk", leaving md=month and day part
set md=%chunk:~0,-4%
echo.%md%
REM Take last one or two characters of "md" as day
set day=%md:~2,2%
echo %day%
<强>输出强>
09222015
2015
09
2
我使用DOSTips.com计算了以上所有内容。