递归目录的文件扩展名总计?

发布于 2024-08-14 16:26:21 字数 274 浏览 4 评论 0原文

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

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

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

有什么想法吗?

谢谢! 罗恩

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

淤浪 2024-08-21 16:26:21

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

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
安稳善良 2024-08-21 16:26:21

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

示例:在 dos 提示符下写入 >; at \\localhost dir /s *.zip (本地主机可以是 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.

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.
娇纵 2024-08-21 16:26:21

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

du *zip

查看GNU 工具

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

du *zip

check out GNU tools.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文