windows - 如何显示 FULLNAME 的长度

标签 windows powershell filenames

how can i get the length of the full path of a filename?

我成功地以递归方式获取目录结构中的所有文件,现在我尝试获取完整路径的长度:

get-childitem y:\ -rec | where {!$_.PSIsContainer} |
select-object FullName, LastWriteTime, $($_.fullname).length | export-csv -notypeinformation -delimiter '|' -path file.csv

我的问题是这样的:$($_.fullname).length:

Select-Object : Null parameter. Expecting one of the following types: {System.String, System.Management.Automation.Scri ptBlock}. At line:2 char:14
+ select-object <<<<  FullName, LastWriteTime, $($_.fullname).length | export-csv -notypeinformation -delimiter '|' -pa th file.csv
    + CategoryInfo          : InvalidArgument: (:) [Select-Object], NotSupportedException
    + FullyQualifiedErrorId : DictionaryKeyUnknownType,Microsoft.PowerShell.Commands.SelectObjectCommand

如何获取文件全名的长度?

最佳答案

在 select cmdlet 中创建自定义表达式。像这样:

get-childitem y:\ -rec | where {!$_.PSIsContainer} |
select-object FullName, LastWriteTime, @{n="FullNameLength";e={ $_.fullname.length }} |
export-csv -notypeinformation -delimiter '|' -path file.csv

n = 名称,e = 表达式。您也可以使用他们的全名。 llabelname 的替代品。无论您以哪种方式编写它们,您最终都会得到一个自定义属性。 :)

关于windows - 如何显示 FULLNAME 的长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16551047/

相关文章:

powershell - 解析具有多个IP的DNS地址

python - 定义一次 ID 号并在每个文件路径中使用它

Eclipse 自动完成文件名

c++ - 如何通过文件扩展名引用文件夹中的文件

c++ - ID3D11DeviceContext::Map 性能低下

windows - Paperclip my Image 无法被 'identify' 命令识别。 (运行 Windows)

c# - 当互联网连接或断开连接时收到通知

windows - 运行时错误 : Cannot read property 'push' of undefined

amazon-web-services - AWS PowerShell 自定义 SSO 回调 : There is no Runspace available to run scripts in this thread

powershell - 如何在哈希表中查找多值名称?