batch script delete file containining certain chars

前端 未结 2 1296
执念已碎
执念已碎 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:12

    The /s switch exists on quite a few commands (including del)

    del /s "C:\TEST\TEST2\*.TXT"
    

    The help for del /? says:

    /S            Delete specified files from all subdirectories.
    
    0 讨论(0)
  • 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"
    
    0 讨论(0)
提交回复
热议问题