Solved

file size via cmd/bat or vbs in terms of MBs

Posted on 2014-11-25
10
355 Views
Last Modified: 2014-11-28
Hi;

I need a script bat/cmd/vbs that sorts the files of C drive in terms of MB on command prompt.

I don't need an installer solution like TreeSize.

Is there any in place?

Regards.
0
Comment
Question by:jazzIIIlove
[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
  • 6
  • 3
10 Comments
 
LVL 16

Expert Comment

by:Brian Pringle
ID: 40465121
What are you trying to accomplish?  If you are trying to get a list of all files on the hard drive within all folders, you can open an administrative command prompt and issue the following command.

dir /a /s /os

/a --> Show all files
/s --> Show files in all subfolders
/os --> Order the files by size (can also use /o-s)

Is that what you are needing?

If you want, you can write that out to a file by changing it to

dir /a /s /os > c:\dirList.txt
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40465127
There is a portable tree size util which can run without installing afaik.  If you want batch or VBScript I have a few batches that may be of use here, e.g. second two show you the biggest 20 files in a directory and subdirs you choose, first one total size in subdir.

http://scripts.dragon-it.co.uk/links/batch-subdir-folder-size
http://scripts.dragon-it.co.uk/links/batch-biggest-files-in-folders
http://scripts.dragon-it.co.uk/links/vbscript-biggest-files-in-folders

You can sort files by size but only in one dir from a dir command.  If you add /s it will sort them within each dir.

dir /o-s

If you really want to you can get a CSV file of any directory structure of all files with something like this which you could put in excel etc:

@echo off
pushd c:\startdir
for /f "tokens=*" %%F in ('dir /b /a-d /s') do echo "%%~dpF","%%~fxF",%%~zF > "%userprofile%\desktop\file-list.csv"
popd
start "" "%userprofile%\desktop\file-list.csv"

Powershell if OK gives other options

Steve
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40465130
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 12

Author Comment

by:jazzIIIlove
ID: 40465238
A 3rd party program is out of question but i will give a try for the script. My aim is to see sorted files and folders w.r.t size
0
 
LVL 12

Author Comment

by:jazzIIIlove
ID: 40466517
Hi;

I used;

@echo off
pushd c:\startdir
for /f "tokens=*" %%F in ('dir /b /a-d /s') do echo "%%~dpF","%%~fxF",%%~zF > "%userprofile%\desktop\file-list.csv"
popd
start "" "%userprofile%\desktop\file-list.csv"

to use it I created a startdir directory as it was giving an error on line 2. I also created file-list.csv but now it gives file not found error on console. Am i missing something?

Regards.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40466722
Sorry I should have said the "pushd" line was to take it to the directory under which you wanted the info.  If you want the whole C: drive then it is going to make you a file with one line per file on the whole dir.  If you wan that change the line to

pushd c:\

Steve
0
 
LVL 12

Author Comment

by:jazzIIIlove
ID: 40466749
Hi Steve;

Seems fine except for the bytes. I want to have it MB and I added the /1048576 but it is treated as string. Any remedy?

Regards.
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 40467708
You could use formulas that turn it into value:

=VALUE(C1/1024/1024)

or we could turn it into Mb in the batch file, or indeed if only files over certain size interested then include those?

Are you only wanting, say, files over 10Mb etc?

Steve
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40467710
Another way since we are talking Excel... if that is acceptable a few lines of VBA could scan down a directory structure and populate a spreadsheet for you.  Say what you are after and will see what I can knock up.

Steve
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 40470666
if you do want to look at other ways just say... exceand macros in vba is great way of finding info and presenting it...
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

A procedure for exporting installed hotfix details of remote computers using powershell
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

718 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