刪除當前目錄下指定文件或者文件夾的批處理

不多說,貼代碼!

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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章