IDDQD
IDDQD

Reputation: 3731

Windows Batch selective deletion

I would like to delete all subdirectories named Debug Release x86 x64 from a particular location while excluding all .git subdirectories. I can easily do this in Linux (find -type d -name Debug -and -not .git -delete or something along those lines).

What did I do wrong here? FINDSTR with lowercase debug release keywords is meant to be an exclusion, I need a case sensitive search.

FOR /R C:\code /D %%I IN (DIR /S /B Debug Release x86 x64 ^| FINDSTR /V \. ^| FINDSTR /V debug ^| FINDSTR /V release) DO ECHO %%I

Upvotes: 0

Views: 74

Answers (2)

user7818749
user7818749

Reputation:

It seems you just want to just recursively delete a folder that starts with debug in a specific path?:

@cd /d "C:\code"
@for /f "delims=" %%i in ('dir /b /s /ad "debug*"') do @echo @rmdir /S/Q "%%~fi"

just remove @echo once you are happy with the results. If I misunderstood your question, then please let me know, but that is what you pretty much shown with your linux find string.

Upvotes: 2

double-beep
double-beep

Reputation: 5504

Use the following code:

@echo off
setlocal EnableDelayedExpansion

pushd "dir_with_subfolders"
for /F "delims=" %%A IN ('dir /S /B /AD "Debug Release x86 x64"') do (
    set "loc=%%~fA"
    if "!loc:\.git\=!" == "!loc!" (
        rd /s /q "%%~fA"
    )
)
popd
pause & exit /b

Upvotes: 2

Related Questions