删除当前目录下指定文件或者文件夹的批处理

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/qq_15345551/article/details/73839050

不多说,贴代码!

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


猜你喜欢

转载自blog.csdn.net/qq_15345551/article/details/73839050
今日推荐