I have a script with a GUI that pops up the Windows Explorer and allows a user to choose a file to export the data too. However, I would like to manipulate some files inside the directory that they choose but when I try to use Split-Path
on the filename I am given this error:
Set-Location : Cannot find drive. A drive with the name 'System.Windows.Forms.TextBox, Text' does not exist.
Is there a way to remove the beginning part of that returned text and only get the path text inside?
//users selected path from GUI Note* this is the path but it is selected by the gui button through file explorer
$UsersPath = "C:\username\desktop\MyFolder\myFile.csv"
$newPath = Split-Path -Path "$UsersPath"
Set-Location "$newPath.Text"
//In this case, $newPath = System.Windows.Forms.TextBox, Text: C:\Users\username\Desktop\myFolder
I have tried using .Text
and .ToString
to no avail.
Below is my code that lets me open a Dialog box to ask the user to choose a file.
function open_CSV_File{
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$openFileDialog.InitialDirectory = "C:\";
$OpenFileDialog.Filter = "csv files (*.csv)|*.csv"
"
if ($OpenFileDialog.ShowDialog() -eq "OK"){
$textbox_BrowseForCSV.Text = $OpenFileDialog.FileName
}
}