如何列出所有文件夹通过批处理文件大小 [英] How to list all folder with size via batch file

查看:633
本文介绍了如何列出所有文件夹通过批处理文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在任一TXT或CSV格式它们的文件夹和大小的列表中选择一个简单的解决方案。

I want a simple solution for list of folders and size of them in either txt or csv format.

我用这个code的文件夹列表

I use this code for folder list

dir C:\Temp\*.* /b /a:d > C:\folderList.txt

电流输出

<<folderList.txt>>
folder1
folder2
folder3

所需的输出

<<folderList.txt>>
folder1 # 100 MB
folder2 # 30 MB
folder3 # 110 MB

只要它会生成每个文件夹的大小..
我怎么能继续?任何帮助

Simply it would generate the size of each folder.. How can I proceed?? any help

推荐答案

有关每个文件夹列表中,使用 DIR 命令检索文件夹下的文件的大小

For each folder in the list, use dir command to retrieve the size of the files under the folder

@echo off
    setlocal disabledelayedexpansion

    set "folder=%~1"
    if not defined folder set "folder=%cd%"

    for /d %%a in ("%folder%\*") do (
        set "size=0"
        for /f "tokens=3,5" %%b in ('dir /-c /a /w /s "%%~fa\*" 2^>nul ^| findstr /b /c:"  "') do if "%%~c"=="" set "size=%%~b"
        setlocal enabledelayedexpansion
        echo(%%~nxa # !size!
        endlocal
    )

    endlocal

有遍历指示的文件夹(如参数到批处理文件,或当前目录传递如果没有放慢参数)。

It iterates over the indicated folder (passed as parameter to the batch file, or current directory if there is no paramter).

有关它里面的每个文件夹(为/ D )的递归 DIR 命令内<$内部执行C $ C>为命令,从它的输出,在最后的总结线(由 FINDSTR )被解析(即标记命令)和所有的文件这个子文件夹下的总规模检索。然后名称(和扩展若有)的文件夹,并在它的元件的尺寸是呼应安慰

For each folder inside it (for /d) a recursive dir command is executed inside the inner for command, and from its output, the summary line at the end (extracted by findstr) is parsed (the tokens in for command) and the total size of all the files under this subfolder is retrieved. Then the name (and extension if it has) of the folder and the size of the elements under it is echoed to console.

如果一个文件需要被创建,该批次的输出重定向到一个文件

If a file needs to be created, redirect the output of the batch to a file

getSizes.cmd "c:\temp" > C:\folderList.txt

这篇关于如何列出所有文件夹通过批处理文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆