hello
Sorry my english is not so good
i have a question / problem with the browse folder function
when i choose a folder and set a variable with this folder , adding a subfolder the path is ok
$Back_Rec_Path = $folderbrowserdialog2.SelectedPath
$global:DestPath = $Back_Rec_Path + "\BACKUP\" + $Env:USERNAME # zb.: C:\Backup\Username...
the $destpath variabe is then ok, like d:\test\backup\
but when i choose a root drive like d:\ the $destpath is d:\\backup
now i have to backslash
what i make wrong
a solution was the following
The following is a safe way to join multiple path segments.
$global:DestPath = [system.io.path]::Combine($Back_Rec_Path.'BACKUP',$Env:USERNAME)
But this only works with powershell 5
it not working with v2 what is most installed on our win 7 clients
how i mus t change the script to run in v2
thx
Peter
Scripting Question
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: Scripting Question
i no that i should not use it
but i have no choice
join-path
have you got an example
or is it possible to include v5 runtime in an compiled exe
but i have no choice
join-path
have you got an example
or is it possible to include v5 runtime in an compiled exe
Re: Scripting Question
Note that [system.io.path]::Combine is a PS2/Net2 method. It works in ALL versions of PwoerShell.
See: https://docs.microsoft.com/en-us/dotnet ... mework-2.0
See: https://docs.microsoft.com/en-us/dotnet ... mework-2.0
Re: Scripting Question
ok i try i again
what i mean with runtime
is it possible to build an exe file with psv5 runtime is included
so it run also when on the target computer is no ps or an old version
what i mean with runtime
is it possible to build an exe file with psv5 runtime is included
so it run also when on the target computer is no ps or an old version
Re: Scripting Question
sorry for my question but on machines with v2 ps that didnt work
$global:DestPath = [system.io.path]::Combine($Back_Rec_Path.'BACKUP',$Env:USERNAME)
the scrippt didnt create a folder with backup on that drive i select
when i switch to a machine with ps 5 all work
$global:DestPath = [system.io.path]::Combine($Back_Rec_Path.'BACKUP',$Env:USERNAME)
the scrippt didnt create a folder with backup on that drive i select
when i switch to a machine with ps 5 all work
Re: Scripting Question
i know
$buttonBrowseFolder_Click = {
if ($folderbrowserdialog2.ShowDialog() -eq 'OK')
{
$textboxFolder.Text = $folderbrowserdialog2.SelectedPath
$Back_Rec_Path = $folderbrowserdialog2.SelectedPath
Update-ListBox $ListBox1 "create Backup Directory / read Backup Directory" -Append
$global:DestPath = [system.io.path]::Combine($Back_Rec_Path,'BACKUP', $Env:USERNAME)
Update-ListBox $ListBox1 "create Log Folder / read Log Folder" -Append
$global:DestPathLog = $DestPath + "\!LOG" #
$global:LogFile = $DestPathLog + "\Robocopy_Profil_copy.txt"
If (!(test-path $DestpathLog)) #sollte das Zielverzeichnis nicht vorhanden sein, läuft Robocopy wegen der LOG-Datei in einen Fehler...
{ New-Item -ItemType Directory -Force -Path $DestpathLog }
#$tabcontrol1.Enabled = $true
}
}
$buttonBrowseFolder_Click = {
if ($folderbrowserdialog2.ShowDialog() -eq 'OK')
{
$textboxFolder.Text = $folderbrowserdialog2.SelectedPath
$Back_Rec_Path = $folderbrowserdialog2.SelectedPath
Update-ListBox $ListBox1 "create Backup Directory / read Backup Directory" -Append
$global:DestPath = [system.io.path]::Combine($Back_Rec_Path,'BACKUP', $Env:USERNAME)
Update-ListBox $ListBox1 "create Log Folder / read Log Folder" -Append
$global:DestPathLog = $DestPath + "\!LOG" #
$global:LogFile = $DestPathLog + "\Robocopy_Profil_copy.txt"
If (!(test-path $DestpathLog)) #sollte das Zielverzeichnis nicht vorhanden sein, läuft Robocopy wegen der LOG-Datei in einen Fehler...
{ New-Item -ItemType Directory -Force -Path $DestpathLog }
#$tabcontrol1.Enabled = $true
}
}