Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Search from FileDialog

$
0
0

Hello,

I am new to PowerShell, so please cooperate.

I use a script to delete lines and and modify the lines with this.

$FileLocation = “C:\company\data”  

$FileFilter = "11092014.txt"   

.... other script lines....

Every time i need to change the file name and run the script to get results.

Now, i want a file search Dialog which will select the file. This script i downloaded from internet which serves the purpose but i don't know how to get the directory in $FileLocation and $FileFilter with this script. If some one can please help me to achieve it.

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 "C:\company\data" -Filter “Text File (*.txt)|*.txt”


Viewing all articles
Browse latest Browse all 6937

Trending Articles