列出隐藏的子目录和大小

列出隐藏的子目录和大小

本文介绍了列出隐藏的子目录和大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 PowerShell 获取子目录及其大小的列表.

I need to get a list of sub-directories with their sizes using PowerShell.

以下 PowerShell 代码执行我想要的操作,但不适用于隐藏目录.

The following PowerShell code does what I want, but it does not work with hidden directories.

Get-ChildItem | Where-Object { $_.PSIsContainer } | ForEach-Object { $_.Name + ": " + "{0:N2}" -f ((Get-ChildItem $_ -Recurse | Measure-Object Length -Sum -ErrorAction SilentlyContinue).Sum / 1MB) + " MB" }

我尝试在 Windows 中显示隐藏目录,但这不起作用.现在,我只是确保每个子目录都没有隐藏,但这并不理想.是否有一个简单的参数可以强制此代码获取隐藏文件和文件夹的信息?

I tried showing hidden directories in Windows, but that does't work. For now, I just make sure every sub-directory is not hidden, but this is not ideal. Is there like a simple parameter that can force this code to get information for hidden files and folders?

最好,我希望它与 PowerShell 2 一起使用.

Preferably, I'd like this to work with PowerShell 2.

推荐答案

将导致它包含隐藏的文件和目录.

The -Force argument for Get-ChildItem will cause it to include hidden files and directories.

Get-ChildItem -Force | Where-Object { $_.PSIsContainer } | ForEach-Object { $_.Name + ": " + "{0:N2}" -f ((Get-ChildItem $_ -Recurse -Force | Measure-Object Length -Sum -ErrorAction SilentlyContinue).Sum / 1MB) + " MB" }

这篇关于列出隐藏的子目录和大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 10:14