batch Dir usage listing

Posted on 2004-11-04
Medium Priority
Last Modified: 2008-02-01
I have a "users" dir with all my users home dir,

I would like to have a batch file to check all dir and output the dir name and size like,
to a file

user1 296mb

user2 100mb

user3 512mb
Question by:CMILLER
  • 6
  • 5
LVL 97

Expert Comment

by:Lee W, MVP
ID: 12500740
Rather then creating a script - which could be done, but probably take a while, I'd recommend downloading DIRUSE.EXE from http://www.microsoft.com/windows2000/techinfo/reskit/tools/existing/diruse-o.asp

This tool does EXACTLY that with various options.  I'll try to post exactly what options you would use to get such output.

Author Comment

ID: 12500750
that will work
LVL 97

Accepted Solution

Lee W, MVP earned 2000 total points
ID: 12500767
This is the help/usage screen from the command:

DIRUSE displays a list of disk usage for a directory tree(s). Version 1.20

DIRUSE [/S | /V] [/M | /K | /B] [/C] [/,] [/Q:# [/L] [/A] [/D] [/O]] [/*] DIRS

/S    Specifies whether subdirectories are included in the output.
/V    Output progress reports while scanning subdirectories.  Ignored if /S is specified.
/M    Displays disk usage in megabytes.
/K    Displays disk usage in kilobytes.
/B    Displays disk usage in bytes (default).
/C    Use Compressed size instead of apparent size.
/,    Use thousand separator when displaying sizes.
/L    Output overflows to logfile .\DIRUSE.LOG.
/*    Uses the top-level directories residing in the specified DIRS
/Q:#    Mark directories that exceed the specified size (#) with a "!".
    (If /M or /K is not specified, then bytes is assumed.)
/A    Specifies that an alert is generated if specified sizes are exceeded.
    (The Alerter service must be running.)
/D    Displays only directories that exceed specified sizes.
/O    Specifies that subdirectories are not checked for specified size
DIRS    Specifies a list of the paths to check.

Note:    Parameters can be typed in any order. And the '-' symbol can be
    used in place of the '/' symbol.

    Also, if /Q is specified, then return code is ONE if any directories are found that
    exceed the specified sizes.  Otherwise the return code is ZERO.

Example: diruse /s /m /q:1.5 /l /* c:\users

The command you would use for listing of user directory sizes would be:
diruse /m /, /* d:\users
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

LVL 97

Expert Comment

by:Lee W, MVP
ID: 12500772
Assuming your users home folders were D:\USERS\<username>

Author Comment

ID: 12500796
yea, they are

is there a way to output to a file?
LVL 97

Expert Comment

by:Lee W, MVP
ID: 12500823
ALMOST Anything that spits out information in a DOS window can be sent to a file by appending "> filename.ext" to the end of the command.

So to put that info into a file, you can use:

diruse /m /, /* d:\users > diruse.log

Author Comment

ID: 12500847
That works, thanks

LVL 97

Expert Comment

by:Lee W, MVP
ID: 12500862
One of these days, I'm going to put together a web site to refer people to, but here's a little more on file redirection:

There's two primary outputs in a DOS window - STANDARD OUT (also known as StdOut) and STANDARD ERROR (also known as StdErr).  By default, both of these OUTput to the screen.  But that can be changed using the ">" and ">>" characters at the end of a command.

For example, if you type "DIR" in a dos window and hit enter, you see a directory listing.  If you want this listing to go to a file, you can say DIR > DIR.TXT and nothing will show up on the screen, but a file called DIR.TXT will be created with what WOULD have shown on the screen.  It's important to note that the ">" character will create the filename specified after it and if the file ALREADY exists, it will OVERWRITE it, effectively erasing the old file.  You CAN append to the file by using a double sign - ">>" Here's an example:


Executing the above two commands results in a file that contains ONLY the directory listing of D - the output from DIR C:\ was destroyed when the file was overwriten by DIR D:\.


Executing the above two commands results in a file that contains BOTH the directory from c: AND the directory from D:

Sometimes you might want to ensure both standard error and standard out go to the same file.  To do this, you would simply append a 2>&1 or 2>>&1.  Why does this work?  Well:

"1>" and ">" are effectively the same.  the 1 represents standard out - and is the default when you just say ">".  Standard Error is referred to as 2.  So by saying:
DIR C:\ > DIR.TXT 2>&1 you are saying to send the ERROR information to the SAME file as the standard output.  With DIR you're not likely to see many instances that use Standard error.  But especially with copy and other commands, errors can occur.  Failure to specify you also want standard error to be sent to a file means your log is basically a SUCCESS ONLY log.  

You can also specify each goes to a different file.  For example:
All errors will be recorded in DIR.ERR while all successes (regular text output) will be recorded in DIR.TXT

Hope this was useful.

NOTE: programs that pop up a window with the help info will NOT work with standard out and standard error - but those that dump info to a DOS window will ALMOST always work with it - though sometimes you have to figure out which output it's using (the NET command is strange like this).

Author Comment

ID: 12500899
very useful thanks,

another question,

I have been trying to figure out over the last few days on how to use msbacli.exe, hfnetchk.exe, and qchain.exe
to update my pc's, I am running sus but I need to update faster that microsoft puts patches out and I have a lab
thats not on the network that needs to stay patched

I think I have all my cli down to what I want, basically what I would like is to either run a command line to get all info
and have it patch based on other files or have someone help build a gui of some sort with say VB,
either way I want it simple to update.

any suggestions?

LVL 97

Expert Comment

by:Lee W, MVP
ID: 12500961
I'm sorry - I can't help much on that one.  I've used HFNETCHK - but not the other apps.  But I applaud your efforts to stay up to date on patches.  If you are concerned about security (and you seem to be), I'd check out (and subscribe to) the NTBUGTRAQ mailing list.  See http://www.ntbugtraq.com/

Author Comment

ID: 12500972

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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…
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…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

840 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