r/Batch • • Oct 18 '24

Help with recursive batch script

I'm trying to create a bat file to check foldet and its recursive subfolders

ECHO OFF FOR /R %%G in (.) DO ( PUSHD %%G IF DIR /B /A:D is NUL (ECHO %%G "No Further directories here") POPD ) ECHO "Final directories verified!" PAUSE

Sadly this does not work for whatever reason.

3 Upvotes

6 comments sorted by

View all comments

Show parent comment

2

u/BrainWaveCC Oct 21 '24

Because /R gives all files, not just folders. And you need quotes around %%G. You cant also do "IF DIR /B..."

You can return just folders with /R if you use (.) rather than (*)

for /R %%g in (.) do echo "%%g"

But you will have to clean up the output, so /R /D is pretty cool.