I am trying to delete all folders on all drives with the above naming pattern, however only on the first folder level, i.e directly below the drive letter, like for example:
F:\this folder's name contains FOO and should be deleted
...without confirmation nor error message (e.g. in case no folders are found), with a batchfile.
I've found this: delete all folders with tmp in name using batch file and am wondering if the solution from there is a good starting point?
@echo off
set dir="c:\FOLDERLOCATION\"
FOR /D /R %dir% %%X IN (*.tmp) DO RMDIR /S /Q "%%X"
pause
exit
Read and follow
FOR
- Conditionally perform a command several times.. You could apply either FOR-Folders, or FOR-Command Results as follows:FOR-Folders (disadvantages: case insensitive; wildcards allow no regex-like pattern so we need to run a loop more times).
FOR-Command Results in combination with
findstr
(advantages:findstr
independently allows both case sensitive and regex-like search pattern):A disadvantage is that
dir
list is generated statically so we need to redirect error messages using2>NUL