Counting Files in Folders and Sub Folders

April 22, 2010 at 22:07:34
Specs: Windows XP
Hi guys,

I'm trying to work out how to create a CSV file which will allow me to find out the number of files in a directory and any sub-directories, but not as a grand total.

I need it to have the folder structure and then the number of files (not including any sub-folders)


C:\Level 1\ 10
C:\Level 1\Sub Level 1\ 0
C:\Level 1\Sub Level 1\next level 1\ 5
C:\Level 1\Sub Level 2\ 5
C:\Level 1\Sub Level 3\ 4
C:\Level 1\Sub Level 3\next level 1\ 12

I would like to open this in Excel so that the folder path is column A and the number of files at that level is column B.

Any ideas?

See More: Counting Files in Folders and Sub Folders

Report •

April 22, 2010 at 22:18:27
Post this in the Programming forum here:

Home Page

Report •

April 23, 2010 at 12:05:41
@echo off & setlocal enabledelayedexpansion
set cnt=0
for /f "tokens=1-2*" %%a in ('dir /s ^|findstr "Directory File(s)"') do (
set /a test="cnt%%2"
if !test! equ 0 (set pth=%%c) else (>> tree.csv echo !pth!,%%a)
set /a cnt+=1
excel tree.csv

Report •

Related Solutions

Ask Question