1 @echo off 2 title test 3 set tmpdir=tmpdir 4 if exist %tmpdir%\nul (rmdir /S /Q %tmpdir%) else if exist %tmpdir% (del /F %tmpdir%) 5 md %tmpdir% 6 cd %tmpdir% 7 :loop 8 set /a c = %c% + 1 9 set tmp=%random% 10 md %tmp% 11 for /f "delims= " %%i in ('date /t') do set name=%%i 12 set name=%name:/=.%_%time:~,8% 13 set name=%name::=.% 14 set name=%name:~5,17%.%random% 15 set name=%name: =0% 16 (ren %tmp% %name%) & (echo %c%.创建目录【%tmp%】成功,并重命名为【%name%】) 17 if %c% lss 20 goto loop
18 echo 请进入%tmpdir%目录下查看后再按任意键继续 19 pause>nul 20 cd ..
21 rmdir /S /Q %tmpdir%
突然发现其中这行有问题,
1 (ren %tmp% %name%) & (echo %c%.创建目录【%tmp%】成功,并重命名为【%name%】)
因为获取时间中间部分有空格出现,会造成ren命令语法不正确,所以最好用零填充。
1 set name=%name: =0%
@echo off title test set tmpdir=tmpdir if exist %tmpdir%\nul (rmdir /S /Q %tmpdir%) else if exist %tmpdir% (del /F %tmpdir%) md %tmpdir% cd %tmpdir% :loop set /a c = %c% + 1 set tmp=%random% md %tmp% set name=%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%.%random% (ren "%tmp%" "%name%") & (echo %c%.创建目录【%tmp%】成功,并重命名为【%name%】) if %c% lss 20 goto loop echo 请进入%tmpdir%目录下查看后再按任意键继续 pause>nul cd .. rmdir /S /Q %tmpdir%