JJJ
JJJ

Reputation: 65

How to count folders in batch

I have a folder structure like this

I want to count how many folders i have one level down from where i am now and also know how to count it 2 levels down and so on, i couldnt find the right command to go deep in each level for instance this script show me all folders but i want to see only one level down or 2 levels down

Here is example of what i have

@echo off

del count.txt

setlocal EnableDelayedExpansion

set current=blank

FOR /D %%G in ("*") DO set current=%%G&& call:count

goto end

:count

set count=0

for %%A in (!current!\*) do set /a count+=1

echo !current!:!count!>>"count.txt"

:end

Upvotes: 2

Views: 1161

Answers (1)

Compo
Compo

Reputation: 38589

Now that you've played around with it a little, try this:

@ECHO OFF
SET "LODC=0"
(   FOR /D %%G IN (*) DO (FOR /D %%H IN ("%%G\*") DO (SET/A LODC+=1
        CALL ECHO %%H:%%LODC%%)))>"count.txt"

Upvotes: 1

Related Questions