且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

批处理脚本删除文件containining某些字符

更新时间:2023-12-05 19:52:22

试试这个:

@echo off & setlocal
set "MySearchString=X"
for /f "delims=" %%i in ('dir /b /s /a-d ^| findstr /i "%MySearchString%"') do echo del "%%~i"

设置变量 MySearchString 来的字符或字符串搜索和删除回声命令,如果输出OK。

Set the variable MySearchString to the character or string to search and remove the echo command, if the output is OK.

您还可以指定 MySearchString 仅文件名:

You can also specify the MySearchString for the file name only:

@echo off & setlocal
set "MySearchString=T"
for /r %%a in (*) do for /f "delims=" %%i in ('echo("%%~na" ^| findstr /i "%MySearchString%"') do echo del "%%~fa"