Как создать флажок по выбранной папке в powershell
Мне нужно создать флажок Автоматически в зависимости от выбранной папки. Я создаю ComboBox, а затем в ComboBox я могу выбрать, какую папку я хочу выбрать. Внутри моей папке, у меня есть какой-то файл. Файл состоит из некоторого файла расширения. Мне просто нужно выбрать 2 файла расширения из папки, например(*.txt и *.csv).
После того как я выберу папку, флажок будет создан автоматически, общая сумма флажка зависит от того, сколько файлов существует в этой папке с определенным расширением(*.txt и *.csv).
В моем коде я уже делаю некоторые вещи, а именно выбираю папку, которую мне нужно выбрать, но все еще борюсь с флажком. Кто-нибудь может мне помочь, пожалуйста. Огромное спасибо. Я очень благодарен Вам за помощь.
Что я уже пробовал:
Add-Type -AssemblyName PresentationFramework Add-Type -AssemblyName System.Windows.Forms [System.Windows.Forms.Application]::EnableVisualStyles() # $Global:status = "inactive" # $Global:array = New-Object System.Collections.Generic.List[System.Object] $Form = New-Object system.Windows.Forms.Form $Form.BackColor = "#f6f6f6" $Form.AutoSize = $true $Form.FormBorderStyle = "FixedDialog" $Form.MaximizeBox = $false $Form.startposition = "centerscreen" $Form.WindowState = 'Maximized' $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(35,80) $Label1.Font = 'Microsoft Sans Serif,12,style=Bold' $Label1.ForeColor = "#000000" $Button3 = New-Object system.Windows.Forms.Button $Button3.BackColor = "#136aa4" $Button3.ForeColor = "#ffffff" $Button3.text = "Done" $Button3.width = 90 $Button3.height = 32 $Button3.UseCompatibleTextRendering = $True $Button3.location = New-Object System.Drawing.Point(1700,920) $Button3.Font = 'Microsoft Sans Serif,10' $Button3.Visible = $false $Button2 = New-Object system.Windows.Forms.Button $Button2.BackColor = "#136aa4" $Button2.ForeColor = "#ffffff" $Button2.text = "Delete" $Button2.width = 90 $Button2.height = 32 $Button2.UseCompatibleTextRendering = $True $Button2.location = New-Object System.Drawing.Point(1600,920) $Button2.Font = 'Microsoft Sans Serif,10' $Button2.Visible = $false $Panel = New-Object System.Windows.Forms.TableLayoutPanel $panel.Dock = "Fill" $panel.ColumnCount = 1 $panel.RowCount = 1 $panel.CellBorderStyle = "single" $panel.ColumnStyles.Add((new-object System.Windows.Forms.ColumnStyle([System.Windows.Forms.SizeType]::Percent, 100))) $panel.RowStyles.Add((new-object System.Windows.Forms.RowStyle([System.Windows.Forms.SizeType]::Percent, 100))) $Groupbox1 = New-Object system.Windows.Forms.Groupbox $Groupbox1.text = "Handling" $Groupbox1.Font = 'Microsoft Sans Serif,9' $Groupbox1.AutoSize = $true $Groupbox1.ForeColor = "#032d5d" $Groupbox1.location = New-Object System.Drawing.Point(8,13) $Groupbox1.Padding = New-Object -TypeName System.Windows.Forms.Padding -ArgumentList (0,5,5,0) $Groupbox1.Dock = "fill" $Groupbox2 = New-Object system.Windows.Forms.Groupbox $Groupbox2.text = "Information" $Groupbox2.Font = 'Microsoft Sans Serif,9' $Groupbox2.AutoSize = $true $Groupbox2.ForeColor = "#032d5d" $Groupbox2.Dock = "None" $Groupbox1.Height $Groupbox1.Width $g2w = $Groupbox1.Width * 9.2 $g2h = $Groupbox1.Height * 7 $Groupbox2.location = New-Object System.Drawing.Point(35,203) $Groupbox2.size = New-Object System.Drawing.Size($g2w,$g2h) $ComboBox1 = New-Object system.Windows.Forms.ComboBox $ComboBox1.BackColor = "#e8f3ff" $ComboBox1.width = 180 $ComboBox1.height = 20 $ComboBox1.location = New-Object System.Drawing.Point(100,75) $ComboBox1.Font = 'Microsoft Sans Serif,12' $ComboBox1.AutoSize = $true $ImageList = @(Get-ChildItem -Directory "D:\Process") foreach ($img in $ImageList) { $ComboBox1.Items.Add($img) } $Form.controls.AddRange(@($Panel)) $Panel.controls.AddRange(@($Groupbox1)) $Groupbox1.Controls.AddRange(@($Groupbox2, $ComboBox1, $Label1, $Button3, $Button2)) [void]$Form.ShowDialog()
###Обновленный
Я обновляю свой сценарий. Но файл появляется только 1, Как только я нажимаю на папку. И когда Я изменяюсь, чтобы щелкнуть другую папку, она не появляется файл.
Add-Type -AssemblyName PresentationFramework Add-Type -AssemblyName System.Windows.Forms [System.Windows.Forms.Application]::EnableVisualStyles() $Global:status = "inactive" $Global:array = New-Object System.Collections.Generic.List[System.Object] $Form = New-Object system.Windows.Forms.Form $Form.text = "BPS Image Automation Utility" $Form.BackColor = "#f6f6f6" $Form.AutoSize = $true $Form.FormBorderStyle = "FixedDialog" $Form.MaximizeBox = $false $Form.startposition = "centerscreen" $Form.WindowState = 'Maximized' $Label1 = New-Object system.Windows.Forms.Label $Label1.text = "Please select the image" $Label1.AutoSize = $true $Label1.width = 25 $Label1.height = 10 $Label1.location = New-Object System.Drawing.Point(50,50) $Label1.Font = 'Microsoft Sans Serif,10' $Label1.ForeColor = "#000000" $label1.AutoSize = $true $Button3 = New-Object system.Windows.Forms.Button $Button3.BackColor = "#136aa4" $Button3.ForeColor = "#ffffff" $Button3.text = "Done" $Button3.width = 90 $Button3.height = 32 $Button3.AutoSize = $true $Button3.UseCompatibleTextRendering = $True $Button3.UseVisualStyleBackColor = $False # $Button3.location = New-Object System.Drawing.Point(1700,920) $Button3.Font = 'Microsoft Sans Serif,10' # $Button3.Visible = $false $Button2 = New-Object system.Windows.Forms.Button $Button2.BackColor = "#136aa4" $Button2.ForeColor = "#ffffff" $Button2.text = "Delete" $Button2.width = 90 $Button2.height = 32 $Button2.UseCompatibleTextRendering = $True $Button2.UseVisualStyleBackColor = $False $Button2.AutoSize = $true # $Button2.location = New-Object System.Drawing.Point(1600,920) $Button2.Font = 'Microsoft Sans Serif,10' # $Button2.Visible = $false $Panel = New-Object System.Windows.Forms.TableLayoutPanel $panel.Dock = "Fill" $panel.ColumnCount = 1 $panel.RowCount = 1 $panel.CellBorderStyle = "single" $panel.ColumnStyles.Add((new-object System.Windows.Forms.ColumnStyle([System.Windows.Forms.SizeType]::Percent, 100))) $panel.RowStyles.Add((new-object System.Windows.Forms.RowStyle([System.Windows.Forms.SizeType]::Percent, 100))) $Groupbox1 = New-Object system.Windows.Forms.Groupbox $Groupbox1.text = "Job Handling" $Groupbox1.Font = 'Microsoft Sans Serif,9' $Groupbox1.AutoSize = $true $Groupbox1.ForeColor = "#032d5d" $Groupbox1.location = New-Object System.Drawing.Point(8,13) $Groupbox1.Padding = New-Object -TypeName System.Windows.Forms.Padding -ArgumentList (0,5,5,0) $Groupbox1.Dock = "fill" $Groupbox1.UseCompatibleTextRendering = $True $Groupbox2 = New-Object system.Windows.Forms.Groupbox $Groupbox2.text = "Job Information" $Groupbox2.Font = 'Microsoft Sans Serif,9' $Groupbox2.AutoSize = $true $Groupbox2.ForeColor = "#032d5d" $Groupbox2.Dock = "None" $Groupbox2.UseCompatibleTextRendering = $True $ComboBox1 = New-Object system.Windows.Forms.ComboBox $ComboBox1.BackColor = "#e8f3ff" $ComboBox1.width = 190 $ComboBox1.height = 20 $ComboBox1.location = New-Object System.Drawing.Point(35,80) $ComboBox1.Font = 'Microsoft Sans Serif,12' $ComboBox1.AutoSize = $true $ImageList = @(Get-ChildItem -Directory "D:\Process") foreach ($img in $ImageList) { $ComboBox1.Items.Add($img) } $ComboBox1.Add_Click({ if($ComboBox1.SelectedItem){ $Checkbox.Visible = $true } }) $Checkboxes += New-Object System.Windows.Forms.CheckBox $Checkboxes = @() $y = 20 $files = Get-ChildItem "D:\Process\$img" -Filter *.txt, *.csv $files foreach ($file in $files) { $Checkbox = New-Object System.Windows.Forms.CheckBox $Checkbox.Text = $file $Checkbox.Location = New-Object System.Drawing.Size(10,$y) $Checkbox.Size = New-Object System.Drawing.Size(330,20) $y += 30 $Groupbox2.Controls.Add($Checkbox) $Checkboxes += $Checkbox $Checkbox.Visible = $false } if($ComboBox1.SelectedItem -eq "$ImageList") { $ImageList $Checkbox.Visible = $true $Button3.Visible = $true $Button2.Visible = $true } $Form.controls.AddRange(@($Panel)) $Panel.controls.AddRange(@($Groupbox1)) $Groupbox1.Controls.AddRange(@($Groupbox2, $ComboBox1, $Label1, $Button3, $Button2)) [void]$Form.Show() $g2w = $Form.Width - 90 $g2h = $Form.Height - 270 $g2h $Groupbox2.location = New-Object System.Drawing.Point(35,110) $Groupbox2.size = New-Object System.Drawing.Size($g2w,$g2h) $Groupbox2.AutoSize = $true $bt2_w = $g2w - 55 $bt2_h = $g2h + 130 $Button2.location = New-Object System.Drawing.Point($bt2_w,$bt2_h) $bt3_w = $g2w - 160 $Button3.location = New-Object System.Drawing.Point($bt3_w,$bt2_h) $Form.Visible = $false [void]$Form.ShowDialog()