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
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.
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"