7

I am trying to list some of my mp3 files with Powershell.

I have tried

ls C:\test | Format-List -Property Name,Length

which gives me

Name   : testfile.mp3
Length : 10058533

The length is the size of the file which I don't care for at this moment.

Knowing that I can choose duration in File Explorer for a column heading I thought to re-write the above as

ls C:\test | Format-List -Property Name,Duration

but what I get is

Name   : testfile.mp3

How can I tell Powershell to return the minutes and seconds for the duration? Or even just the seconds. Thanks in advance

Darius
  • 2,206

1 Answers1

11

To get the length of an mp3, probably the easiest way is to make use of what explorer uses, a Shell objekt.

I'm afraid I don't have a one-liner for you, but you can always make a script that you call.

$path = 'M:\Musikk\awesome_song.mp3'
$shell = New-Object -COMObject Shell.Application
$folder = Split-Path $path
$file = Split-Path $path -Leaf
$shellfolder = $shell.Namespace($folder)
$shellfile = $shellfolder.ParseName($file)

write-host $shellfolder.GetDetailsOf($shellfile, 27); 

More information can be found here: http://powershell.com/cs/blogs/tobias/archive/2011/01/07/organizing-videos-and-music.aspx

Edit: The reason this method is necessary is because the length information resides with the other metadata of the file.

Martin
  • 1,327
  • I wasn't asking for one-liner so no deduction there :) And yes this does give me what I am asking for now I need to loop it for multiples files :) Thanks – Darius Jan 20 '14 at 23:57