[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

List files and their sizes in subfolders

Posted on 2013-05-22
8
Medium Priority
?
409 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 58

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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
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 58

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

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

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…
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…
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…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

650 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