Powershell 获取路径的FileMetaData拆分

Powershell 获取路径的FileMetaData拆分,powershell,Powershell,我正在使用下面的代码从我正在阅读的文件结构中提取元数据。我还想将Name字段拆分为只包含文件名而不包含扩展名。我会使用BaseName,但我没有利用getchilditem,所以这是不可能的。如何使用PSPath-split或类似的方法将该值放入每个文件的新列中?这是在一堆文件中循环,然后导出为txt文件 Get-FileMetaData -folders 'C:|Pics' -properties Name, Path, Comments, Dimensions, Width, Height

我正在使用下面的代码从我正在阅读的文件结构中提取元数据。我还想将
Name
字段拆分为只包含文件名而不包含扩展名。我会使用
BaseName
,但我没有利用
getchilditem
,所以这是不可能的。如何使用
PSPath-split
或类似的方法将该值放入每个文件的新列中?这是在一堆文件中循环,然后导出为txt文件

Get-FileMetaData  -folders 'C:|Pics' -properties Name, Path, Comments, Dimensions, Width, Height | Sort-Object Name |
    select Name, Path, Comments, Dimensions, Width, Height | Export-Csv '\\nzsdf01\SCRIPTS\test.txt' -encoding UTF8 -NoTypeInformation

假设您正在使用选项中的代码:

  • 修改该函数,使其也包含BaseName

    $hash.Clear()
    $hash.BaseName = [IO.Path]::GetFileNameWithoutExtension($file.Name)
    
    并在函数的参数中指定BaseName:

    Get-FileMetaData -folders 'r:\foo' -properties BaseName, Path, Comments
    
  • 选择中使用计算属性

    Get-FileMetaData -folders 'r:\foo' -properties Name, Path, Comments |
        select @{N='BaseName'; E={[IO.Path]::GetFileNameWithoutExtension($_.Name)}}, 
            Path, Comments | .........
    

  • 嗯,您可以通过在该函数中添加
    BaseName
    属性。我的意思是您可以编辑该函数的代码。否则,请使用
    选择中的计算属性。与属性非常接近。再次感谢你的帮助!