0

I am using the below to pull through metadata from a file structure I am reading. I am also wanting to split out the Name field to just include the filename without extension. I would use BaseName but i'm not leveraging Get-ChildItem so this isn't possible. How would I use PSPath -split or something similar to put this value in a new column against each file? This is looping through a bunch of files then exporting to a txt file.

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
Carlos
  • 217
  • 1
  • 4
  • 13
  • Well, you can add `BaseName` property inside that function by [stripping the extension from Name](https://stackoverflow.com/a/12503910). – wOxxOm Mar 22 '17 at 01:26
  • I meant you can edit the code of the function. Otherwise use calculated properties in `select`. – wOxxOm Mar 22 '17 at 01:38

1 Answers1

1

Assuming you're using the code from that answer your options are:

  1. modify the function to also include BaseName

    $hash.Clear()
    $hash.BaseName = [IO.Path]::GetFileNameWithoutExtension($file.Name)
    

    and specify BaseName in the parameters for the function:

    Get-FileMetaData -folders 'r:\foo' -properties BaseName, Path, Comments
    
  2. use calculated properties in select

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