我需要递归地获取目录的大小。我每个月都要这样做,所以我想做一个PowerShell脚本来做它。
我该怎么做呢?
发布于 2009-05-01 17:34:26
如果您对包含隐藏文件和系统文件的大小感兴趣,那么应该将-force参数与Get-ChildItem一起使用。
发布于 2012-05-14 22:42:38
下面是获取特定文件扩展名大小的快速方法:
(gci d:\folder1 -r -force -include *.txt,*.csv | measure -sum -property Length).Sum
发布于 2012-11-28 07:37:37
感谢那些在这里发帖的人。我采用了这些知识来创建这个:
# Loops through each directory recursively in the current directory and lists its size.
# Children nodes of parents are tabbed
function getSizeOfFolders($Parent, $TabIndex) {
$Folders = (Get-ChildItem $Parent); # Get the nodes in the current directory
ForEach($Folder in $Folders) # For each of the nodes found above
{
# If the node is a directory
if ($folder.getType().name -eq "DirectoryInfo")
{
# Gets the size of the folder
$FolderSize = Get-ChildItem "$Parent\$Folder" -Recurse | Measure-Object -property length -sum -ErrorAction SilentlyContinue;
# The amount of tabbing at the start of a string
$Tab = " " * $TabIndex;
# String to write to stdout
$Tab + " " + $Folder.Name + " " + ("{0:N2}" -f ($FolderSize.Sum / 1mb));
# Check that this node doesn't have children (Call this function recursively)
getSizeOfFolders $Folder.FullName ($TabIndex + 1);
}
}
}
# First call of the function (starts in the current directory)
getSizeOfFolders "." 0
https://stackoverflow.com/questions/809014
复制相似问题