PowerShell script to get path of wav files

294 views Asked by At

With below PowerShell script I am able to get Name, Size, DateCreated, Length of wav files from folder but I also want path of each files.

Please help me to update this code.

$folder= 'C:\Users\r.shishodia\Desktop\2-8-2018\web'
$com = (New-Object -ComObject Shell.Application).NameSpace($folder)
for ($i = 0; $i -lt 64; $i++) {
    $name = $com.GetDetailsOf($com.Items, $i)
    if ($name -eq 'Length') { $lengthattribute = $i}
}
$com.Items() | ForEach-Object {
    [PSCustomObject]@{
        Name = $_.Name
        Size = $com.GetDetailsOf($_, 1)
        DateCreated = $com.GetDetailsOf($_, 4)
        Length = $com.GetDetailsOf($_, $lengthattribute)
    }
} | Export-Csv -Path C:\Users\r.shishodia\Desktop\report.csv -Encoding ascii -NoTypeInformation

enter image description here

1

There are 1 answers

4
Vivek Kumar Singh On BEST ANSWER

Try something like this -

Get-ChildItem $folder | % {$_.FullName}

The FullName parameter will give you the path for each file.

If we try your approach, then -

If you take a look at $com.Items(), you will see there is already a Path property in it. So you can directly add that in your custom PSObject and export it via CSV.

$com.Items() | ForEach-Object {
    [PSCustomObject]@{
        Name = $_.Name
        Size = $com.GetDetailsOf($_, 1)
        DateCreated = $com.GetDetailsOf($_, 4)
        Length = $com.GetDetailsOf($_, $lengthattribute)
        Path = $_.Path
    }
} | Export-Csv -Path C:\Users\r.shishodia\Desktop\report.csv -Encoding ascii -NoTypeInformation