batch script delete file containining certain chars

前端 未结 2 1361
执念已碎
执念已碎 2021-01-25 11:46

I have almost no experience in batch, but now I need a script to delete all files that contain certain characters in their names from a folder and its subfolders

2条回答
  •  忘掉有多难
    2021-01-25 12:14

    Try this:

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

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

    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"
    

提交回复
热议问题