关于批处理的问题,谢谢
写了一个批处理删除当前日期之前的文件
for %%i in (C:\ghost\*.csv) do (
set filetime_a=%%~ti
if not "%filetime_a:~2,2%%filetime_a:~4,3%%filetime_a:~7,3%"=="%date:~-8%" del /f %%i
)
但是运行的时候发现一个问题
C:\ghost>tt.bat
C:\ghost>for %i in (C:\ghost\*.csv) do (
set filetime_a=%~ti
if not "07/02/28" == "07/02/28" del /f %i
)
C:\ghost>(
set filetime_a=2007/02/07 17:31
if not "07/02/28" == "07/02/28" del /f C:\ghost\TEMPSHOHIN.csv
)
C:\ghost>(
set filetime_a=2007/02/27 15:06
if not "07/02/28" == "07/02/28" del /f C:\ghost\b.csv
)
C:\ghost>(
set filetime_a=2007/02/28 10:43
if not "07/02/28" == "07/02/28" del /f C:\ghost\a.csv
)
"%filetime_a:~2,2%%filetime_a:~4,3%%filetime_a:~7,3%"总是取到最晚生成的一个文件的日期,不知道是为什么啊?
为了把运行结果显示的清楚一些,我把
"%filetime_a:~2,2%%filetime_a:~4,3%%filetime_a:~7,3%"
改成了"%filetime_a%"再运行
C:\ghost>tt.bat
C:\ghost>for %i in (C:\ghost\*.csv) do (
set filetime_a=%~ti
if not "2007/02/28 10:43" == "07/02/28" del /f %i
)
C:\ghost>(
set filetime_a=2007/02/07 17:31
if not "2007/02/28 10:43" == "07/02/28" del /f C:\ghost\TEMPSHOHIN.csv
)
C:\ghost>(
set filetime_a=2007/02/27 15:06
if not "2007/02/28 10:43" == "07/02/28" del /f C:\ghost\b.csv
)
C:\ghost>(
set filetime_a=2007/02/28 10:43
if not "2007/02/28 10:43" == "07/02/28" del /f C:\ghost\a.csv
)
这样可以明显看到"%filetime_a%"的值
请高人给解释一下,谢谢了