<# This form was created using POSHGUI.com a free online gui designer for PowerShell
.NAME
ArcDirMatcher.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,291'
$Form.text = "ArcDirMatcher"
$Form.TopMost = $false
$TextBox1 = New-Object system.Windows.Forms.TextBox
$TextBox1.multiline = $false
$TextBox1.width = 277
$TextBox1.height = 20
$TextBox1.location = New-Object System.Drawing.Point(21,63)
$TextBox1.Font = 'Microsoft Sans Serif,17'
$Button1 = New-Object system.Windows.Forms.Button
$Button1.text = "..."
$Button1.width = 60
$Button1.height = 30
$Button1.location = New-Object System.Drawing.Point(316,63)
$Button1.Font = 'Microsoft Sans Serif,10'
$Label1 = New-Object system.Windows.Forms.Label
$Label1.text = "Select folder with archives (recursive):"
$Label1.AutoSize = $true
$Label1.width = 25
$Label1.height = 10
$Label1.location = New-Object System.Drawing.Point(21,34)
$Label1.Font = 'Microsoft Sans Serif,12'
$Label2 = New-Object system.Windows.Forms.Label
$Label2.text = "Select path of extracted folders (non-recursive):"
$Label2.AutoSize = $true
$Label2.width = 25
$Label2.height = 10
$Label2.location = New-Object System.Drawing.Point(21,130)
$Label2.Font = 'Microsoft Sans Serif,12'
$TextBox2 = New-Object system.Windows.Forms.TextBox
$TextBox2.multiline = $false
$TextBox2.width = 273
$TextBox2.height = 20
$TextBox2.location = New-Object System.Drawing.Point(21,161)
$TextBox2.Font = 'Microsoft Sans Serif,17'
$Button2 = New-Object system.Windows.Forms.Button
$Button2.text = "..."
$Button2.width = 60
$Button2.height = 30
$Button2.location = New-Object System.Drawing.Point(316,161)
$Button2.Font = 'Microsoft Sans Serif,10'
$Button3 = New-Object system.Windows.Forms.Button
$Button3.text = "Start"
$Button3.width = 90
$Button3.height = 30
$Button3.location = New-Object System.Drawing.Point(155,230)
$Button3.Font = 'Microsoft Sans Serif,12'
$Form.controls.AddRange(@($TextBox1,$Button1,$Label1,$Label2,$TextBox2,$Button2,$Button3))
$Button1.Add_Click({
$objForm = New-Object System.Windows.Forms.FolderBrowserDialog
$objForm.Description = "Select folder containing archives"
$objForm.SelectedPath = [System.Environment+SpecialFolder]'MyComputer'
$objForm.ShowNewFolderButton = $false
$result = $objForm.ShowDialog()
if ($result -eq "OK") {
$TextBox1.Text = $objForm.SelectedPath
} else {
$TextBox1.Text = ""
}
})
$Button2.Add_Click({
$objForm = New-Object System.Windows.Forms.FolderBrowserDialog
$objForm.Description = "Select folder containing extracted archives"
$objForm.SelectedPath = [System.Environment+SpecialFolder]'MyComputer'
$objForm.ShowNewFolderButton = $false
$result = $objForm.ShowDialog()
if ($result -eq "OK") {
$TextBox2.Text = $objForm.SelectedPath
} else {
$TextBox2.Text = ""
}
})
$Button3.Add_Click({
if (($TextBox2.Text -ne "") -and ($TextBox1.Text -ne "")) {
Collect-Archives $TextBox2.Text $TextBox1.Text
}
})
#endregion events }
#endregion GUI }
#Write your logic code here
Function Collect-Archives {
param (
[string]$path,
[string]$drive
)
$Button3.Text = 'Working'
$archives = Get-ChildItem -Path "$($drive)\*" -Recurse -Include *.arc,*.arj,*.zip,*.rar,*.7z # add more extensions if necessary
$folders = Get-ChildItem -Path $path -Directory # add -Recurse if you want to recurse through the folders also
$total = 0
Out-File -FilePath ($drive + '\ArcDirMatcher.txt') -InputObject "Rem -- Replace 'Matches:' with 'rmdir /s /q' in a text editor,`r`nRem -- then rename the extension from '.txt' to '.cmd'`r`nRem -- and run it to remove folders.`r`n" -Encoding utf8
for ($i = 0; $i -lt $archives.Count; $i++) {
$folderName = ([io.path]::GetFileNameWithoutExtension($archives[$i]))
for ($j = 0; $j -lt $folders.Count; $j++) {
if ((Split-Path $folders[$j] -Leaf) -eq $folderName) {
$total += 1
$text = "Rem Match $($total): $($archives[$i])`r`nMatches: `"$($folders[$j].FullName)`"`r`n"
Out-File -FilePath ($drive + '\ArcDirMatcher.txt') -InputObject $text -Append -Encoding utf8
}
}
}
$Button3.Text = 'Start'
if ($total -ne 0) {
Invoke-Item ($drive + '\ArcDirMatcher.txt')
}
}
[void]$Form.ShowDialog()