Displaying sub-directories

Ref: displaying the time-duration/length (hh:mm:ss) see last/below.
Question #2 (in 3 parts):
part 1: Can this script be made to include the sub directories also? - DOS dir cmd uses the ‘/s’ switch include sub-directories
part 2: If not, can a script be modified to append data to an existing CSV file?
part 3: Can the script also report the file-path where the audio file is stored?
I have sub-folders that also contain MP3 files (which are called track 1, tract 2, etc.):
…\Dos.Mundos.Audio.Activity.1of8
…\Dos.Mundos.Audio.Activity.2of8
…\Dos.Mundos.Audio.Activity.3of8
…\Dos.Mundos.Audio.Activity.4of8
…\Dos.Mundos.Audio.Activity.5of8
…\Dos.Mundos.Audio.Activity.6of8
…\Dos.Mundos.Audio.Activity.7of8
…\Dos.Mundos.Audio.Activity.8of8

Thanks, Tracey
Windows7 Powershell 5.1
Question #1 was about using code page 1252

$MediaFiles = @('*.mp3','*.mp4')
$Directory = 'D:\Users\Public\Public.Language\Pronounce it Perfectly in Spanish 2e\Pronounce it Perfectly in Spanish 2e.Down.Load'
$Shell = New-Object -ComObject Shell.Application
Get-ChildItem -Path $Directory -Recurse -Include $MediaFiles |
ForEach-Object {
    $Folder = $Shell.Namespace($_.DirectoryName)
    $File = $Folder.ParseName($_.Name)
    $Duration = $Folder.GetDetailsOf($File, 27)
    [PSCustomObject] @{
        Name     = $_.Name
        Size     = $_.length
        Duration = $Duration
    }
} | Export-Csv -Path 'C:\Users\Acer\MediaSE.csv' -NoTypeInformation

If you just want to get name, file path, and append to existing csv file, use similar to code example below. Your existing csv file must have name,length,fullname headers or just export to new csv file.

Get-ChildItem -Path $Directory -Recurse | Where-Object {$_.Extension -in '.mp3','.mp4'} | 
Select-Object Name,Length,FullName | 
Export-csv -Append 'C:\Users\Acer\MediaSE.csv' -NoTypeInformation

The Recurse parameter ensures that subfolders are included. Are you sure they are mp3 files and aren’t being filtered by the extensions in the $MediaFiles array?

Please read the help for the commands that you’re running.
Get-Help Export-Csv will show that there is an Append parameter.

To get the path, you can either use the FullName property instead of just Name or if you want it in its own column:

[PSCustomObject] @{
        Name      = $_.Name
        Directory = $_.DirectoryName
        Size      = $_.length
        Duration  = $Duration
    }

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.