递归文件扩展名的目录?

时间:2009-12-14 19:51:44

标签: recursion batch-file dos totals

我想知道特定目录树中zip文件(或任何其他扩展名)使用了多少磁盘空间。这是否可以在命令行上(在批处理程序中)?

我可以列出它们,即:dir / s * .zip 或使用“forfiles”:forfiles / p d:\ wincap / s / m * .zip / c“cmd / c echo @fsize”

我需要在批处理程序中使用它,因为我想在100多台服务器(w2k3)上运行它。 我习惯使用unix / linux,dos让我很头疼;)

想法?

谢谢! 罗恩

3 个答案:

答案 0 :(得分:0)

您可以尝试 at 命令,也许它可以帮助远程运行命令。

示例:在dos提示符下写> at \\localhost dir /s *.zip(localhost可以是192.bla.bla.bla,你要调用的是远程)


其他帮助

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.

答案 1 :(得分:0)

以下是找到的修改版本: 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

为了避免溢出,它会立即将值转换为MB,因此它将会舍入,从而低估总数,但希望这至少会使您走上正确的轨道。将其保存为dirsize.bat并将其作为第一个参数调用,并将模式作为第二个参数匹配:

dirsize c:\ *.zip

答案 2 :(得分:0)

如果你可以将东西下载到你的机器上,你仍然可以使用unix工具,比如du。

du *zip

结帐GNU tools