Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is another solution for this commented to describe each part of the script:</p> <pre><code>@Echo OFF REM Important that Delayed Expansion is Enabled setlocal enabledelayedexpansion REM This sets what folder the batch is looking for and the root in which it starts the search: set /p foldername=Please enter the foldername you want to delete: set /p root=Please enter the root directory (ex: C:\TestFolder) REM Checks each directory in the given root FOR /R %root% %%A IN (.) DO ( if '%%A'=='' goto end REM Correctly parses info for executing the loop and RM functions set dir="%%A" set dir=!dir:.=! set directory=%%A set directory=!directory::=! set directory=!directory:\=;! REM Checks each directory for /f "tokens=* delims=;" %%P in ("!directory!") do call :loop %%P ) REM After each directory is checked the batch will allow you to see folders deleted. :end pause endlocal exit REM This loop checks each folder inside the directory for the specified folder name. This allows you to check multiple nested directories. :loop if '%1'=='' goto endloop if '%1'=='%foldername%' ( rd /S /Q !dir! echo !dir! was deleted. ) SHIFT goto :loop :endloop </code></pre> <p>You can take the <code>/p</code> out from in front of the initial variables and just enter their values after the <code>=</code> if you don't want to be prompted:</p> <pre><code>set foldername= set root= </code></pre> <p>You can also remove the <code>echo</code> in the loop portion and the <code>pause</code> in the end portion for the batch to run silently.</p> <p>It might be a little more complicated, but the code can be applied to a lot of other uses.</p> <p>I tested it looking for multiple instances of the same foldername <code>qwerty</code> in <code>C:\Test</code>:</p> <pre><code>C:\Test\qwerty C:\Test\qwerty\subfolder C:\Test\test\qwerty C:\Test\test\test\qwerty </code></pre> <p>and all that was left was:</p> <pre><code>C:\Test\ C:\Test\test\ C:\Test\test\test\ </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload