Link to home
Start Free TrialLog in
Avatar of Chris Miller
Chris MillerFlag for United States of America

asked on

batch Dir usage listing

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
Avatar of Lee W, MVP
Lee W, MVP
Flag of United States of America image

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.
Avatar of Chris Miller

ASKER

that will work
ASKER CERTIFIED SOLUTION
Avatar of Lee W, MVP
Lee W, MVP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Assuming your users home folders were D:\USERS\<username>
yea, they are

is there a way to output to a file?
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
That works, thanks

-Chris
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:

DIR C:\ > DIR.TXT
DIR D:\ > DIR.TXT

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:\.

DIR C:\ > DIR.TXT
DIR D:\ >> DIR.TXT

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:
DIR C:\ 1> DIR.TXT 2> DIR.ERR
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).
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?

-Chris
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/
thanks