問題描述:ide
寫一個bat文件,刪除文件名符合特定規則,且更改日期在某個日期以前的全部目錄spa
@echo offinput
echo The program will select the E:\deployment\ as default working path.it
setlocal enabledelayedexpansionio
::WORKING DIRECTORYclass
set workPath=E:\deployment\date
echo The directory created before the date will be deleted,file
set /p deleteDate=please input the date.(yyyy/MM/dd or yyyy-MM-dd):select
set delete_date=%deleteDate:~0,4%%deleteDate:~5,2%%deleteDate:~8,2%tab
echo These directory have been selected
for /D /R %workPath% %%i in (*_T*) do (
set file_date=%%~ti
set file_date=!file_date:~6,4!!file_date:~0,2!!file_date:~3,2!
if !file_date! lss %delete_date% (
echo %%i %%~ti
)
)
echo.
echo.
set /p choice=Do you want to delete them? (Y or N):
if /i "%choice%" EQU "Y" (
for /D /R %workPath% %%i in (*_T*) do (
set file_date=%%~ti
set file_date=!file_date:~6,4!!file_date:~0,2!!file_date:~3,2!
if !file_date! lss %delete_date% (
echo deleting %%i %%~ti
rd /S /Q %%i
)
)
echo.
echo Success,You have deleted the selected directory.
)
if /i "%choice%" EQU "N" (
echo You cancel the progress.
)
endlocal