Anlage des Repos
This commit is contained in:
30
examples/PowerShell/Select-FileDialog.ps1
Normal file
30
examples/PowerShell/Select-FileDialog.ps1
Normal file
@@ -0,0 +1,30 @@
|
||||
# Note: store in your profile for easy use
|
||||
# Example use:
|
||||
# $file = Select-FileDialog -Title "Select a file" -Directory "D:\scripts" -Filter "Powershell Scripts|(*.ps1)"
|
||||
|
||||
function Select-FileDialog
|
||||
{
|
||||
param([string]$Title,[string]$Directory,[string]$Filter="All Files (*.*)|*.*")
|
||||
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
|
||||
$objForm = New-Object System.Windows.Forms.OpenFileDialog
|
||||
$objForm.InitialDirectory = $Directory
|
||||
$objForm.Filter = $Filter
|
||||
$objForm.Title = $Title
|
||||
$Show = $objForm.ShowDialog()
|
||||
If ($Show -eq "OK")
|
||||
{
|
||||
Return $objForm.FileName
|
||||
}
|
||||
Else
|
||||
{
|
||||
Write-Error "Operation cancelled by user."
|
||||
}
|
||||
}
|
||||
|
||||
$file = Select-FileDialog -Title "Select a file" -Directory "D:\scripts" -Filter "Powershell Scripts (*.ps1)|*.ps1"
|
||||
|
||||
#multiple file category arguments should not include extra space:
|
||||
#-Filter “Text files (*.txt) | *.txt | All files (*.*) | *.*”
|
||||
#does not work — only show *.* filter.
|
||||
#-Filter “Text files (*.txt)|*.txt|All files (*.*)|*.*”
|
||||
#works.
|
||||
Reference in New Issue
Block a user