?
Solved

List files and their sizes in subfolders

Posted on 2013-05-22
8
Medium Priority
?
404 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 56

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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
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
 
LVL 11

Accepted Solution

by:
paultomasi earned 800 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 56

Assisted Solution

by:Bill Prew
Bill Prew earned 200 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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

800 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