㈠ 批處理如何在指定文件夾內搜索某個關鍵字,包含這個關鍵字的文件或文件夾要刪除
打開文本編輯器,例如記事本,並輸入以下內容:
@echo off
rem 設置搜索路徑和關鍵字
set searchPath=c: est
set searchKey=keyword
rem 查找包含關鍵字的文件
for /f "delims=" %%i in ('dir /b /s /a-d "%searchPath%" ^| findstr /i /c:"%searchKey%"') do (
rem 刪除包含關鍵字的文件
del "%%i"
)
rem 查找包含關鍵字的文件夾
for /f "delims=" %%i in ('dir /b /s /ad "%searchPath%" ^| findstr /i /c:"%searchKey%"') do (
rem 刪除包含關鍵字的文件夾
rd "%%i" /s /q
)
保存文件為 delete.bat,並將文件拖拽到命令行窗口中,按回車鍵運行批處理文件