Solved

List files and their sizes in subfolders

Posted on 2013-05-22
8
389 Views
Last Modified: 2013-05-25
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
0
Comment
Question by:miyahira
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 8

Expert Comment

by:Dipak
ID: 39189516
dir /s This command displays files in specified directory and all subdirectories.
0
 
LVL 1

Author Comment

by:miyahira
ID: 39189538
Yea, but I only want to display SubFolder, FileName and size. No more.
0
 
LVL 52

Expert Comment

by:Bill Prew
ID: 39189572
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
0
 
LVL 1

Author Comment

by:miyahira
ID: 39192633
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
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 11

Accepted Solution

by:
paultomasi earned 200 total points
ID: 39192917
Your best bet is to use 'FOR /R' as in the following command:

@for /r "D:\MainFolder" %a in (*) do @echo %~dpa %~nxa %~za

Open in new window

Or you can try this neat little batch file:

@echo off
setlocal enabledelayedexpansion

for /r "D:\MainFolder" %%a in (*) do (
  set dp=%%~dpa
  echo !dp:~0,-1! %%~nxa %%~za
)

Open in new window

The '!dp:~0,-1!' strips away the trailing '\' (backslash) character from the file's pathname otherwise, '%%~dpa' gives you the drive and path of the file, '%%~nxa' gives you the filename and it's extension (if any) and '%%~za' gives you the file's size.
0
 
LVL 1

Author Comment

by:miyahira
ID: 39192940
Thanks paultomasi, you're the Best!
0
 
LVL 52

Assisted Solution

by:Bill Prew
Bill Prew earned 50 total points
ID: 39193034
Sorry, typo, should be:

@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 %%~zF,"%%~F"
)> "%OutFile%"

Open in new window

~bp
0
 
LVL 11

Expert Comment

by:paultomasi
ID: 39196879
Thank you
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
Concerto provides fully managed cloud services and the expertise to provide an easy and reliable route to the cloud. Our best-in-class solutions help you address the toughest IT challenges, find new efficiencies and deliver the best application expe…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now