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

本文介绍了一个简单的批处理脚本工具,用于在当前目录下按名称批量删除文件或目录。脚本通过用户输入来指定要删除的目标,并提供了警告提示确保操作的安全性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

不多说,贴代码!

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


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值