使用 Powershell 计算文件夹 [英] Counting folders with Powershell

查看:37
本文介绍了使用 Powershell 计算文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有人知道 powershell 2.0 命令/脚本来计算特定文件夹中的所有文件夹和子文件夹(递归;没有文件)(例如 C:\folder1\folder2 中所有子文件夹的数量)?

Does anybody know a powershell 2.0 command/script to count all folders and subfolders (recursive; no files) in a specific folder ( e.g. the number of all subfolders in C:\folder1\folder2)?

此外,我还需要所有叶子"文件夹的数量.换句话说,我只想计算没有子目录的文件夹.

In addition I also need also the number of all "leaf"-folders. in other words, I only want to count folders, which don't have subolders.

推荐答案

您可以使用 get-childitem -recurse 获取当前文件夹中的所有文件和文件夹.

You can use get-childitem -recurse to get all the files and folders in the current folder.

将其传送到 Where-Object 以将其过滤为仅作为容器的文件.

Pipe that into Where-Object to filter it to only those files that are containers.

$files = get-childitem -Path c:\temp -recurse 
$folders = $files | where-object { $_.PSIsContainer }
Write-Host $folders.Count

作为单线:

(get-childitem -Path c:\temp -recurse | where-object { $_.PSIsContainer }).Count

这篇关于使用 Powershell 计算文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆