首页 > 解决方案 > 在 Powershell 中添加返回文件夹大小的函数

问题描述

我正在查询文件夹名称/计数/上次修改的驱动器。但是我还想添加文件夹大小 MB。我已经搜索/尝试了一些选项,但无法让它们工作。

由于某些路径超过 240char,该文件也失败了。是否有解决方法(例如跳过这些文件夹)?

感谢您对我要添加的一行代码的帮助。或对下面的任何更改。非常感谢。

$FOLDER_ROOT = "K:\Docs\"
$OUTPUT_LOCATION = "C:\Users\me\Documents\Powershell_OUT.txt"
Function DirX($directory)
{
    Remove-Item $OUTPUT_LOCATION

    foreach ($singleDirectory in (Get-ChildItem $directory -Recurse -Directory))
    {
        $count = Get-ChildItem $singleDirectory.FullName -File | Measure-Object | %{$_.Count}
        $summary = $singleDirectory.FullName+"|"+$count+"|"+$singleDirectory.LastAccessTime
        Add-Content $OUTPUT_LOCATION $summary
    }
}
DirX($FOLDER_ROOT)

标签: powershell

解决方案


推荐阅读