Something simple in PowerShell because I wanted to see how to get things into a ListView -
was pretty easy after I dumped trying to get it all into a multi-dimensional array first Woohoo! worked out how to create one


EBO.ps1
<# This form was created using POSHGUI.com a free online gui designer for PowerShell
.NAME
EBO.ps1
#>
#region begin GUI{
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
$Form = New-Object system.Windows.Forms.Form
$Form.ClientSize = '400,579'
$Form.text = "EBO"
$Form.BackColor = "#b8e986"
$Form.TopMost = $false
$ListView1 = New-Object system.Windows.Forms.ListView
$ListView1.View = 'Details'
$ListView1.MultiSelect = $false
$ListView1.GridLines = $true
$ListView1.width = 369
$ListView1.height = 442
$ListView1.Anchor = 'top,right,bottom,left'
$ListView1.location = New-Object System.Drawing.Point(15,100)
$TextBox1 = New-Object system.Windows.Forms.TextBox
$TextBox1.multiline = $false
$TextBox1.width = 268
$TextBox1.height = 20
$TextBox1.location = New-Object System.Drawing.Point(15,27)
$TextBox1.Font = 'Microsoft Sans Serif,10'
$Button1 = New-Object system.Windows.Forms.Button
$Button1.text = "..."
$Button1.width = 28
$Button1.height = 25
$Button1.location = New-Object System.Drawing.Point(291,26)
$Button1.Font = 'Microsoft Sans Serif,10'
$Button2 = New-Object system.Windows.Forms.Button
$Button2.text = "Start"
$Button2.width = 60
$Button2.height = 25
$Button2.location = New-Object System.Drawing.Point(325,26)
$Button2.Font = 'Microsoft Sans Serif,10'
$Button3 = New-Object system.Windows.Forms.Button
$Button3.text = "Death by File Size"
$Button3.width = 140
$Button3.height = 25
$Button3.location = New-Object System.Drawing.Point(15,63)
$Button3.Font = 'Microsoft Sans Serif,10'
$Button4 = New-Object system.Windows.Forms.Button
$Button4.text = "Death by Bit Rate"
$Button4.width = 140
$Button4.height = 25
$Button4.location = New-Object System.Drawing.Point(244,63)
$Button4.Font = 'Microsoft Sans Serif,10'
$Label1 = New-Object system.Windows.Forms.Label
$Label1.Text = 'Double-click folder to open'
$Label1.AutoSize = $true
$Label1.Width = 100
$Label1.Height = 10
$Label1.Anchor = 'bottom,left'
$Label1.Location = New-Object System.Drawing.Point(120,552)
$Label1.Font = 'Microsoft Sans Serif,10'
$ToolTip1 = New-Object System.Windows.Forms.ToolTip
$ToolTip1.AutomaticDelay = 500
$ToolTip1.IsBalloon = $true
$ToolTip1.SetToolTip($Button4, "Keep highest bit rate file")
$Form.controls.AddRange(@($Button4))
$ToolTip2 = New-Object System.Windows.Forms.ToolTip
$ToolTip2.AutomaticDelay = 500
$ToolTip2.IsBalloon = $true
$ToolTip2.SetToolTip($Button3, "Keep largest file")
$Form.controls.AddRange(@($Button3))
$ToolTip3 = New-Object System.Windows.Forms.ToolTip
$ToolTip3.AutomaticDelay = 500
$ToolTip3.IsBalloon = $true
$ToolTip3.SetToolTip($Button1, "Select folder")
$Form.controls.AddRange(@($Button1))
$Form.controls.AddRange(@($ListView1,$TextBox1,$Button1,$Button2,$Button3,$Button4,$Label1))
#region gui events {
$ListView1.Add_DoubleClick({
Start-Process ($ListView1.SelectedItems).Text
})
$Button3.Add_Click({
Murder-Them Size
})
$Button4.Add_Click({
Murder-Them BitRate
})
$Button2.Add_Click({
$ListView1.Clear() | Out-Null
$ListView1.Columns.Add('Folder') | Out-Null
$ListView1.Columns.Add('Files') | Out-Null
Get-Folders $TextBox1.Text
})
$Button1.Add_Click({
$objForm = New-Object System.Windows.Forms.FolderBrowserDialog
$objForm.Description = "Select folder"
$objForm.SelectedPath = [System.Environment+SpecialFolder]'MyComputer'
$objForm.ShowNewFolderButton = $false
$result = $objForm.ShowDialog()
if ($result -eq "OK") {
$TextBox1.Text = $objForm.SelectedPath
} else {
$TextBox1.Text = ""
}
})
#endregion events }
#endregion GUI }
#Write your logic code here
Add-Type -AssemblyName Microsoft.VisualBasic
Function Murder-Them {
param (
[string]$sort
)
Write-Host '---'
for ($i = 0; $i -lt $ListView1.Items.Count; $i++ ) {
$files = (Get-MetaData -path $ListView1.Items[$i].Text .mp3)
$temp = @()
for ($j = 0; $j -lt $files.Count; $j++) {
$temp += ,@( $files[$j].'Path', (((Get-Item $files[$j].'Path').Length).ToString()).PadLeft(20, '0') , ($files[$j].'Bit rate' -replace '.{4}$').PadLeft(4, '0') )
}
if ($sort -eq 'Size') {
$temp = $temp | Sort-Object {$_[1]}
} else {
$temp = $temp | Sort-Object {$_[2]}
}
for ($k = 0; $k -lt $temp.Count - 1; $k++) {
[Microsoft.VisualBasic.FileIO.FileSystem]::DeleteFile("$($temp[$k][0])",'OnlyErrorDialogs','SendToRecycleBin')
# Remove-Item -Path "$($temp[$k][0])"
}
}
}
Function Get-MetaData {
PARAM (
[PARAMETER(Mandatory=$true)]
[string]$path = "",
[PARAMETER( Mandatory=$true, HelpMessage="extension eg. .mp3, .txt or .mov")]
[string]$type = "", # 'mp3'
[switch]$recurse
)
if ($recurse) {
$LPath = Get-ChildItem -Path $path -Directory -Recurse
} else {
$LPath = $path
}
$DirectoryCount = 1
$RetrievedMetadata = $true
$OutputList = New-Object 'System.Collections.generic.List[psobject]'
Foreach ($pa in $LPath) {
$shell = New-Object -ComObject shell.application
if ($recurse) {
$objshell = $shell.NameSpace($pa.FullName)
} else {
$objshell = $shell.NameSpace($pa)
}
#Build data list
$count = 0
#Filter on filetype
Measure-Command -Expression { $filter = $objshell.items() | where {$_.path -match $type} } | Out-File -FilePath K:\test.txt
foreach ($file in $filter) {
if ($RetrievedMetadata) {
# Build metanumbers
Write-Verbose "Building MetaIndex for filetype $type"
$Metanumbers = New-Object -TypeName 'System.Collections.Generic.List[int]'
for ($a = 0; $a -le 400; $a++) {
if ($objshell.GetDetailsOf($file, $a)) {
$Metanumbers.Add([int]$a)
}
}
$RetrievedMetadata = $false
Write-Verbose "$($Metanumbers.Count) entries in MetaIndex for filetype $type"
}
$count++
$CurrentDirectory = Get-ChildItem -Path $file.path
try {
Write-Progress -Activity " Getting metadata from $DirectoryCount/$($LPath.count) $($CurrentDirectory[0].DirectoryName)" -Status "Working on $count/$($filter.count) - $($file.Name)" -PercentComplete (($count / $filter.count) * 100) -ErrorAction stop
} catch {}
#Build Hashtable for each file
$Hash = @{}
foreach ($nr in $Metanumbers) {
$PropertyName = $($objshell.GetDetailsOf($objshell.Items, $nr))
$PropertyValue = $($objshell.GetDetailsOf($File, $nr))
$Hash[$PropertyName] = $PropertyValue
}
$Hash.Remove("")
$FileMetaData = New-Object -TypeName PSobject -Property $hash
$OutputList.Add($FileMetaData)
$hash = $null
}
$DirectoryCount++
}
Write-Verbose "MetaData for $($OutputList.count) files found"
return $OutputList
}
Function Get-Folders {
param (
[string]$path
)
$a = Get-ChildItem $path -Recurse -Directory
for ($i = 0; $i -lt $a.Count; $i++) {
$b = (Get-ChildItem $a[$i].FullName -File | Measure-Object).Count
if ($b -gt 1) {
$ListView_Item = New-Object System.Windows.Forms.ListViewItem($a[$i].FullName)
$ListView_Item.SubItems.Add($b)
$ListView1.Items.AddRange(($ListView_Item))
}
}
$ListView1.AutoResizeColumn(1, 1)
$ListView1.AutoResizeColumn(0, 2)
}
[void]$Form.ShowDialog()




The one marked VBR bit rate is actually 224kHz that's why it's remained.
Still no error checking

No progress indicator either

PS. Forgot to mention it deletes to the Recycle Bin.