-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemove Extra Rows WithGUI.ps1
More file actions
executable file
·167 lines (140 loc) · 5.36 KB
/
Remove Extra Rows WithGUI.ps1
File metadata and controls
executable file
·167 lines (140 loc) · 5.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
cls
Function IntroMessage
{
#Message to prompt the user to explain how the program works.
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$userForm = New-Object System.Windows.Forms.Form
$userForm.Text = "Remove Extra Lines"
$userForm.Size = New-Object System.Drawing.Size(580,300)
$userForm.StartPosition = "CenterScreen"
$userForm.AutoSize = $False
$userForm.MinimizeBox = $False
$userForm.MaximizeBox = $False
$userForm.SizeGripStyle= "Hide"
$userForm.WindowState = "Normal"
$userForm.FormBorderStyle="Fixed3D"
#add label1
$userLabel1 = New-Object System.Windows.Forms.Label
$userLabel1.Location = New-Object System.Drawing.Size(150,50)
$userLabel1.Size = New-Object System.Drawing.Size(300,50)
$userLabel1.Text = "This Program will Remove anything more than 40 lines from a txt file."
$userForm.Controls.Add($userLabel1)
#Add direction Label
$userLabel2 = New-Object System.Windows.Forms.Label
$userLabel2.Location = New-Object System.Drawing.Size(150,100)
$userLabel2.Size = New-Object System.Drawing.Size(300,50)
$userLabel2.Text = "The first windows Explorer will allow you to choose the folder where the txt files are located"
$userForm.Controls.Add($userLabel2)
#add button
$CloseButton = New-Object System.Windows.Forms.Button
$CloseButton.Location = New-Object System.Drawing.Size(230,200)
$CloseButton.Size = New-Object System.Drawing.Size(75,23)
$CloseButton.Text = "Close"
$CloseButton.Add_Click({$userForm.Close()})
$userForm.Controls.Add($CloseButton)
#Load Form
$userForm.Topmost = $True
$userForm.Opacity = 0.91
$userForm.ShowIcon = $False
$userForm.Add_Shown({$userForm.Activate()})
[void] $userForm.ShowDialog()
}
Function SecondMessage
{
#Message to prompt the user to explain how the program works.
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$userForm = New-Object System.Windows.Forms.Form
$userForm.Text = "Remove Extra Lines"
$userForm.Size = New-Object System.Drawing.Size(580,300)
$userForm.StartPosition = "CenterScreen"
$userForm.AutoSize = $False
$userForm.MinimizeBox = $False
$userForm.MaximizeBox = $False
$userForm.SizeGripStyle= "Hide"
$userForm.WindowState = "Normal"
$userForm.FormBorderStyle="Fixed3D"
#Add destination Label
$userLabel2 = New-Object System.Windows.Forms.Label
$userLabel2.Location = New-Object System.Drawing.Size(150,100)
$userLabel2.Size = New-Object System.Drawing.Size(300,50)
$userLabel2.Text = "The next windows Explorer will allow you to choose the folder where the new txt files will be saved"
$userForm.Controls.Add($userLabel2)
#add button
$CloseButton = New-Object System.Windows.Forms.Button
$CloseButton.Location = New-Object System.Drawing.Size(230,200)
$CloseButton.Size = New-Object System.Drawing.Size(75,23)
$CloseButton.Text = "Close"
$CloseButton.Add_Click({$userForm.Close()})
$userForm.Controls.Add($CloseButton)
#Load Form
$userForm.Topmost = $True
$userForm.Opacity = 0.91
$userForm.ShowIcon = $False
$userForm.Add_Shown({$userForm.Activate()})
[void] $userForm.ShowDialog()
}
Function Select-FolderDialog
{
param([string]$Description="Select Folder",[string]$RootFolder="Desktop")
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") |
Out-Null
$objForm = New-Object System.Windows.Forms.FolderBrowserDialog
$objForm.Rootfolder = $RootFolder
$objForm.Description = $Description
$objForm.ShowNewFolderButton = $false
$Show = $objForm.ShowDialog()
If ($Show -eq "OK")
{
Return $objForm.SelectedPath
}
Else
{
Write-Error "Operation cancelled by user."
}
}
Function Select-FolderDialog2
{
param([string]$Description="Select Folder",[string]$RootFolder="Desktop")
[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") |
Out-Null
$objForm = New-Object System.Windows.Forms.FolderBrowserDialog
$objForm.Rootfolder = $RootFolder
$objForm.Description = $Description
$Show = $objForm.ShowDialog()
If ($Show -eq "OK")
{
Return $objForm.SelectedPath
}
Else
{
Write-Error "Operation cancelled by user."
}
}
#call functions
IntroMessage
$path = Select-FolderDialog
SecondMessage
$path2 = Select-FolderDialog2
if(Test-Path $path2){
echo("Folder Already Exists")
}
else
{
New-Item -ItemType Directory -path $path2 -Force
echo("Folder created")
}
$files = gci -path $path -filter "*.txt"
foreach($file in $files){
$lineCount = 0
Get-Content $file.FullName |
ForEach-Object{
if($lineCount -lt 40){
$_
$lineCount++
}
else{
}
}|Set-Content "$path2\$file"
}#end of foreach