使用当前日期批量脚本到RENAME文件

时间:2015-06-04 16:30:53

标签: batch-file

我试图简单地重命名文件,用当前日期替换文件名中的日期。我得到“语法不正确错误”

这是我的代码:

echo on
for /f "skip=1" %%x in ('wmic os get localdatetime') do if not defined MyDate set MyDate=%%x
set today=%MyDate:~0,4%-%MyDate:~4,2%-%MyDate:~6,2%


set "_year=%MyDate:~0,4%"
set "_month=%MyDate:~4,2%"
set "_day=%MyDate:~6,2%"

REN C:\Users\xyz125\Documents\Erics's Docs\scripts\"test file (20150112).txt" "test file (%_year%%_month%%_day%).txt"

pause

1 个答案:

答案 0 :(得分:1)

错误的引用:而不是

REN C:\Users\xyz125\Documents\Erics's Docs\scripts\"test file (20150112).txt" "test file (%_year%%_month%%_day%).txt"
rem                                                ^

应该是

REN "C:\Users\xyz125\Documents\Erics's Docs\scripts\test file (20150112).txt" "test file (%_year%%_month%%_day%).txt"
rem ^