BerrKamal
BerrKamal

Reputation: 89

Bat to delete specific folders in subfolders listed in a text file

Bat to delete specific lis of subfolders

In windows xp I have a folder name gaming that contain 100 folders with names games1, games2, games3 ... games100.

And inside every of those folders there is a huge list of subfolders from 1 to 100000.

And I have a name list of the 50000 folders that i want to delete
example of the name list that I want to remove without knowing the name of their parent directory

6383  
6385  
4850  
6395  
6396  
6397  
9865  
6401  
6408  
1200  
...  
..  
.  

Upvotes: 2

Views: 1681

Answers (2)

foxidrive
foxidrive

Reputation: 41234

This expects a list.txt in the d:\folder\gaming folder and it will create "removefolders.bat.txt" in the same folder.

Open that file in Notepad and verify that the correct folders are listed and then you can rename it to .bat and run it to actually delete the folders.

@echo OFF
pushd "d:\folder\gaming"
del "removefolders.bat.txt" 2>nul
for /f "delims=" %%a in ('type "list.txt" ') do (
for /d /r %%b in (*) do if "%%~nxb"=="%%a" >>"removefolders.bat.txt" echo rd /q /s "%%b"
)
popd

Upvotes: 1

Endoro
Endoro

Reputation: 37569

try this:

@echo OFF &SETLOCAL
SET "namelist=list.txt"

for /f "usebackq delims=" %%a in ("%namelist%") do set "$%%a=1"
for /d /r "gaming" %%a in (*) DO IF DEFINED $%%~na ECHO rd /s /q "%%~a"

Look at the output and remove the word echo before rd if it looks good.

Upvotes: 6

Related Questions