views:

242

answers:

3

I want to know how much disk space is being used by zip files (or any other extension) in a particular directory tree. Is this possible on the command line (in a batch program)?

I can list them, ie: dir /s *.zip or using "forfiles": forfiles /p d:\wincap /s /m *.zip /c "cmd /c echo @fsize"

I need it in a batch program, because I want to run it on 100+ servers (w2k3). I am accustomed to unix/linux, and dos is giving me a headache ;)

Ideas?

Thanks! Ron

A: 

You can try at command, maybe it can help run command remotely.

Example : on dos prompt write > at \\localhost dir /s *.zip (localhost can be 192.bla.bla.bla, what you want to call remote)


Additional help

The AT command schedules commands and programs to run on a computer at
a specified time and date. The Schedule service must be running to use
the AT command.

AT [\\computername] [ [id] [/DELETE] | /DELETE [/YES]]
AT [\\computername] time [/INTERACTIVE]
    [ /EVERY:date[,...] | /NEXT:date[,...]] "command"

\\computername     Specifies a remote computer. Commands are scheduled on the
                   local computer if this parameter is omitted.
id                 Is an identification number assigned to a scheduled
                   command.
/delete            Cancels a scheduled command. If id is omitted, all the
                   scheduled commands on the computer are canceled.
/yes               Used with cancel all jobs command when no further
                   confirmation is desired.
time               Specifies the time when command is to run.
/interactive       Allows the job to interact with the desktop of the user
                   who is logged on at the time the job runs.
/every:date[,...]  Runs the command on each specified day(s) of the week or
                   month. If date is omitted, the current day of the month
                   is assumed.
/next:date[,...]   Runs the specified command on the next occurrence of the
                   day (for example, next Thursday).  If date is omitted, the
                   current day of the month is assumed.
"command"          Is the Windows NT command, or batch program to be run.
javaloper
A: 

Here's a modified version of the one found: http://en.kioskea.net/forum/affich-42442-dos-command-batch-file-to-find-a-folder-size

@echo off
setLocal EnableDelayedExpansion
set /a value=0
set /a sum=0 
FOR /R %1 %%I IN (%2) DO (
set /a value=%%~zI/1024/1024
set /a sum=!sum!+!value!
)
@echo Size is: !sum!  MB

In order to avoid overflows it converts values to MB right away so it will round and thus under-report the total but hopefully this puts you on the right track at least. Save it as dirsize.bat and call it with the directory as the first parameter and the pattern to match as the second:

dirsize c:\ *.zip
Chris Haas
Chris, you're a prince among men!This works absolutly perfect for my needs. I was playing with the "%~zI" call, but couldn't quite get them to total. THANKS!
Ron
A: 

if you can download stuffs to your machine, you can still use unix tools, like du.

du *zip

check out GNU tools.

I was using sysinternals du command, and it doesn't work that well... only gives total usage for directories... not file types. I suppose I should have used a unix port or something.
Ron
if you want file types, just provide the extension like what i did, then pipe to awk, eg du *zip | awk '{t+=$1}END{print t}'