Windows下PowerShell输入命令获取指定文件夹和文件大小

发布时间:2020-05-27 09:56:32 作者:Mos 阅读量:4177

1、Windows PowerShell输入以下命令,直接复制粘贴然后回车:

function filesize ([string]$filepath)
{
    if ($filepath -eq $null)
    {
        throw "路径不能为空"
    }
    dir -Path $filepath |
    ForEach-Object -Process {
        if ($_.psiscontainer -eq $true)
        {
            $length = 0
            dir -Path $_.fullname -Recurse | ForEach-Object{
                $length += $_.Length
            }
            $l = $length/1MB
            $_.name + "文件夹的大小为: {0:n2} MB" -f $l
        }else
        {
            $length = 0
            dir -Path $_.fullname -Recurse | ForEach-Object{
                $length += $_.Length
            }
            $l = $length/1MB
            $_.name + "文件的大小为: {0:n2} MB" -f $l
        }
    }
}
如图所示:

1

2、再输入以下命令查看文件(夹)大小,其中filepath参数为你需要查询大小的文件夹,如具体的"C:\Users\Public"或者相对的:

filesize -filepath .\company\
如图所示:

2

文章来源:https://www.i847.cn/article/4845.html

支付宝打赏 微信打赏
©2021 i847.cn
部分内容转自网络,如有损害您的权益,致邮联系:jiang2008wen#126.com,一经证实,立即删除!     我要留言
备案号:蜀ICP备18020563号-1