Solved

List files and their sizes in subfolders

Posted on 2013-05-22
8
399 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 55

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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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 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 55

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

689 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