版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
不多说,贴代码!
delete.bat如下
@echo off
echo current dir: %cd%
echo The script will help you remove the specified file or directory under the current directory
echo Please enter the name or directory of the file you want to delete:
set /p name=
echo The name or directory of the file you entered is:%name%
echo ##################################################################################
echo #Warning: deleted file or file name cannot be restored, please operate carefully!#
echo ##################################################################################
set /p ifContinue=Do you want to continue(y or n):
if "%ifContinue%"=="y" (
echo is continue...
for /f "delims=" %%f in ('dir /s/a-d/b "%name%.*"') do (
echo delete file: %%f
del %%f
)
cd ..
echo current dir: %cd%
for /f "delims=" %%d in ('dir /ad/b/s "%name%"') do (
echo delete dir:%%d
rd /s /q %%d
)
) else (
echo You have canceled the operation!
)
pause