2
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

我如何获得文件全名的长度?

4

1 回答 1

5

在 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= 表达式。您也可以使用他们的全名。llabel是 的替代品name。不管你用哪种方式编写它们,你最终都会得到一个自定义属性。:)

于 2013-05-14T19:25:02.820 回答