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 } } }如图所示:
2、再输入以下命令查看文件(夹)大小,其中filepath参数为你需要查询大小的文件夹,如具体的"C:\Users\Public"或者相对的:
filesize -filepath .\company\如图所示: