使用powershell
1:以管理员身份打开powershell ise
2:将以下文本copy到脚本文件中
#需要搜寻的目标目录
$startFolder = 'C:\Users'
$colItems = (Get-ChildItem -Force $startFolder | Where-Object {$_.PSIsContainer -eq $True} | Sort-Object)
$list = @()
$allSize = 0
foreach ($i in $colItems)
{
$subFolderItems = (Get-ChildItem $i.FullName -recurse | Measure-Object -property length -sum)
$allSize += $subFolderItems.sum
$file = [PSCustomObject]@{
name = $i.name
size = $subFolderItems.sum
}
$list += $file
}
$list = ($list | Sort-Object -Descending -Property size)
Write-Host "****总大小****"
Write-Host (" -- " + "{0:N2}" -f ($allSize / 1GB) + " GB")
Write-Host "****总大小****"
Write-Host
foreach($item in $list)
{
"{0:N2}" -f ($item.size / 1GB) + " GB" + " -- " + $item.name
}
修改$startFolder的值
F5运行脚本(如果脚本文件保存了,则需要先运行一条命令设置脚本执行权限:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force)
*****
请注意,如果嵌套的文件路径太深,或者遇到无权访问的文件夹,计数会失败,所以得到的最终结果未必准确
*****