powershell Get-ChildItem 结果在数组中 [英] powershell Get-ChildItem result in array

查看:72
本文介绍了powershell Get-ChildItem 结果在数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(Get-ChildItem -File -Recurse -Path $path).Fullname 返回全名数组(Get-ChildItem -File -Recurse -Path $path).Name 返回文件名数组但(Get-ChildItem -File -Recurse -Path $path).Length 只返回一个值 - 元素的数量

(Get-ChildItem -File -Recurse -Path $path).Fullname returns array of full names (Get-ChildItem -File -Recurse -Path $path).Name returns array of files names but (Get-ChildItem -File -Recurse -Path $path).Length returns only one value - the count of elements

问题 - 如何以文件长度数组的形式获取结果?

Question - how to get result as array of file lengths ?

推荐答案

您得到的一个值确实是结果数组的长度 - Array 类有一个显式的 Length 属性 优先于属性枚举.

The one value you get is indeed the length of the resulting array - the Array class has an explicit Length property that takes precedence over property enumeration.

要从数组中的每个项目中获取单独的 Length 属性值,请通过管道连接到 Select-ObjectForEach-Object,例如所以:

To get the individual Length property values from each item in the array, pipe to either Select-Object or ForEach-Object, like so:

Get-ChildItem -File -Recurse -Path $path |ForEach-Object -MemberName Length
# or 
Get-ChildItem -File -Recurse -Path $path |Select-Object -ExpandProperty Length

这篇关于powershell Get-ChildItem 结果在数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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