<#
.NAME
Concat-GUI.ps1
#>
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
#region begin GUI{
$Form = New-Object system.Windows.Forms.Form
$Form.ClientSize = '386,237'
$Form.text = "Concat"
$Form.TopMost = $false
$TextBox1 = New-Object system.Windows.Forms.TextBox
$TextBox1.multiline = $false
$TextBox1.width = 230
$TextBox1.height = 20
$TextBox1.location = New-Object System.Drawing.Point(83,25)
$TextBox1.Font = 'Microsoft Sans Serif,10'
$Label1 = New-Object system.Windows.Forms.Label
$Label1.text = "Folder:"
$Label1.AutoSize = $true
$Label1.width = 25
$Label1.height = 10
$Label1.location = New-Object System.Drawing.Point(22,29)
$Label1.Font = 'Microsoft Sans Serif,10'
$Button1 = New-Object system.Windows.Forms.Button
$Button1.text = "..."
$Button1.width = 34
$Button1.height = 25
$Button1.location = New-Object System.Drawing.Point(328,24)
$Button1.Font = 'Microsoft Sans Serif,10'
$TextBox2 = New-Object system.Windows.Forms.TextBox
$TextBox2.multiline = $false
$TextBox2.width = 100
$TextBox2.height = 20
$TextBox2.location = New-Object System.Drawing.Point(83,65)
$TextBox2.Font = 'Microsoft Sans Serif,10'
$Label2 = New-Object system.Windows.Forms.Label
$Label2.text = "Filter:"
$Label2.AutoSize = $true
$Label2.width = 25
$Label2.height = 10
$Label2.location = New-Object System.Drawing.Point(22,69)
$Label2.Font = 'Microsoft Sans Serif,10'
$TextBox3 = New-Object system.Windows.Forms.TextBox
$TextBox3.multiline = $false
$TextBox3.width = 230
$TextBox3.height = 20
$TextBox3.location = New-Object System.Drawing.Point(83,104)
$TextBox3.Font = 'Microsoft Sans Serif,10'
$Button2 = New-Object system.Windows.Forms.Button
$Button2.text = "..."
$Button2.width = 34
$Button2.height = 25
$Button2.location = New-Object System.Drawing.Point(328,103)
$Button2.Font = 'Microsoft Sans Serif,10'
$Label3 = New-Object system.Windows.Forms.Label
$Label3.text = "Output:"
$Label3.AutoSize = $true
$Label3.width = 25
$Label3.height = 10
$Label3.location = New-Object System.Drawing.Point(22,110)
$Label3.Font = 'Microsoft Sans Serif,10'
$CheckBox1 = New-Object system.Windows.Forms.CheckBox
$CheckBox1.text = "Reverse Sort"
$CheckBox1.AutoSize = $false
$CheckBox1.width = 113
$CheckBox1.height = 20
$CheckBox1.location = New-Object System.Drawing.Point(234,149)
$CheckBox1.Font = 'Microsoft Sans Serif,10'
$Button3 = New-Object system.Windows.Forms.Button
$Button3.text = "Start"
$Button3.width = 60
$Button3.height = 30
$Button3.location = New-Object System.Drawing.Point(170,185)
$Button3.Font = 'Microsoft Sans Serif,10'
$Label4 = New-Object system.Windows.Forms.Label
$Label4.text = "Sort by:"
$Label4.AutoSize = $true
$Label4.width = 25
$Label4.height = 10
$Label4.location = New-Object System.Drawing.Point(22,146)
$Label4.Font = 'Microsoft Sans Serif,10'
$ComboBox1 = New-Object system.Windows.Forms.ComboBox
$ComboBox1.text = ""
$ComboBox1.width = 100
$ComboBox1.height = 20
@('Name','Size','Creation','Modification','Accessed') | ForEach-Object {[void
] $ComboBox1.Items.Add
($_)} $ComboBox1.location = New-Object System.Drawing.Point(83,144)
$ComboBox1.Font = 'Microsoft Sans Serif,10'
$ComboBox1.SelectedIndex = 0
$Form.controls.AddRange(@($TextBox1,$Label1,$Button1,$TextBox2,$Label2,$TextBox3,$Button2,$Label3,$CheckBox1,$Button3,$Label4,$ComboBox1))
#region gui events {
$Button1.Add_Click({
$objForm = New-Object System.Windows.Forms.FolderBrowserDialog
$objForm.Description = "Select folder containing files"
$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({
$SaveChooser = New-Object -TypeName System.Windows.Forms.SaveFileDialog
$SaveChooser.ShowDialog()
$TextBox3.Text = $SaveChooser.FileName
})
$Button3.Add_Click({
if ($TextBox2.Text -eq "") { $TextBox2.Text = '*.txt'}
if (($TextBox1.Text -ne "") -and ($TextBox3.Text -ne "")) {
Sort-Files
}
})
#endregion events }
#endregion GUI }
#Write your logic code here
Function Sort-Files {
$files = Get-ChildItem ($TextBox1.Text + '\' + $TextBox2.Text)
if ($CheckBox1.Checked) {
switch ($ComboBox1.SelectedItem) {
'Name' { $sorted = $files | Sort-Object -Property Name -Descending }
'Size' { $sorted = $files | Sort-Object -Property Length -Descending }
'Creation' { $sorted = $files | Sort-Object -Property CreationTime -Descending }
'Modification' { $sorted = $files | Sort-Object -Property LastWriteTime -Descending }
'Accessed' { $sorted = $files | Sort-Object -Property LastAccessTime -Descending }
}
} else {
switch ($ComboBox1.SelectedItem) {
'Name' { $sorted = $files | Sort-Object -Property Name }
'Size' { $sorted = $files | Sort-Object -Property Length }
'Creation' { $sorted = $files | Sort-Object -Property CreationTime }
'Modification' { $sorted = $files | Sort-Object -Property LastWriteTime }
'Accessed' { $sorted = $files | Sort-Object -Property LastAccessTime }
}
}
Merge-Files $sorted
}
Function Merge-Files {
param (
$objects
)
for ($I = 0; $i -lt $objects.Count; $i++) {
Add-Content -Path $TextBox3.Text "`r`n----------`r`n$($objects[$i].Fullname)`r`n----------"
Add-Content -Path $TextBox3.Text -Value (Get-Content $objects[$i])
}
}
[void]$Form.ShowDialog()