Link to home
Create AccountLog in
Avatar of miyahira
miyahiraFlag for Peru

asked on

List files and their sizes in subfolders

Hello,

Is there any easy way to list all files (and their sizes) that are contained in sub folders.
Run something like:

D:\MainFolder\list_files_and_size.bat

And get a list of all files and their sizes in all subfolders of MainFolder?

Thank you
Avatar of Dipak
Dipak
Flag of India image

dir /s This command displays files in specified directory and all subdirectories.
Avatar of miyahira

ASKER

Yea, but I only want to display SubFolder, FileName and size. No more.
Avatar of Bill Prew
Bill Prew

Here's a fairly simple BAT file that will write to a CSV file with the file size and full path.  Then just open the CSV file in Excel to allow reporting, sorting, etc.  Naturally the output format could be changed if this isn't ideal...

@echo off
set BaseDir=D:\MainFolder
set OutFile=logfile.csv
(
  echo Size,Filename
  for /f "tokens=*" %%F in ('dir /s /b /a-d "%BaseDir%"') do echo %%~zI,"%%~I"
)> "%OutFile%"

Open in new window

~bp
Hi billprew,
Unfortunately, command:

dir /s /b /a-d "%BaseDir%

Open in new window


only lists path and file name, as shown in image attached.

It doesn't show size of files.
DirSize.png
ASKER CERTIFIED SOLUTION
Avatar of Paul Tomasi
Paul Tomasi
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Thanks paultomasi, you're the Best!
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Thank you