ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Finished Programs

DONE: Append/Concatenate/Merge text files, but prepend filenames

<< < (3/3)

wraith808:
Guess that’s a no on mine. Well I tried  ;)

I’ll delete the download.
-c.gingerich (October 04, 2018, 10:11 PM)
--- End quote ---

Always good to have alternatives in case needed.  He seems to go with the first solution, which makes sense.  All of the rest of them unless something is wrong with the first solution end up being noise, but not useless.

nkormanik:
c.gingerich, 4wd, wraith808, cranioscopical...  you guys are great.

(Who else did I miss??)

Thanks for your help.

Skwire, another one done.

4wd:
Plus you can add simple GUI's to Powershell scripts, (so much easier than AutoIt):

DONE: Append/Concatenate/Merge text files, but prepend filenames

For the last few Powershell GUIs I've been using PoshGUI to create them rather than screw around in Visual Studio.

Concat-GUI.ps1

--- Code: PowerShell ---<#.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()
Filter defaults to *.txt if it's empty when Start is pressed.

Create a shortcut to run it from with the Target as: %SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -noprofile -executionpolicy bypass -File "Concat-GUI.ps1"

Guess that’s a no on mine. Well I tried  ;)

I’ll delete the download.
-c.gingerich (October 04, 2018, 10:11 PM)
--- End quote ---

No need to, the more the merrier ... I only do this for some mental exercise and I use little to no error checking in my scripts, (because I'm lazy :D ), so something someone else writes is more likely to be PEBKAC proof.

wraith808:
That site is so cool!  Thanks for it!

4wd:
That site is so cool!  Thanks for it!-wraith808 (October 05, 2018, 07:48 PM)
--- End quote ---

You're welcome, can't get my GUIs to save, (after creating an account), using Save never seems to work ... maybe I'm just running too much anti-tracking/ad stuff in the browser, haven't spent the time to work it out yet.

I just end up using copy/paste to get the rough raw code into PoSh ISE and then fiddle around with the values to add/remove/move things.

Navigation

[0] Message Index

[*] Previous page

Go to full version