问题描述:
写一个bat文件,删除文件名符合特定规则,且更改日期在某个日期之前的所有目录
@echo off
echo The program will select the E:\deployment\ as default working path.
setlocal enabledelayedexpansion
::WORKING DIRECTORY
set workPath=E:\deployment\
echo The directory created before the date will be deleted,
set /p deleteDate=please input the date.(yyyy/MM/dd or yyyy-MM-dd):
set delete_date=%deleteDate:~0,4%%deleteDate:~5,2%%deleteDate:~8,2%
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