browse folder function problem

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
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.
Locked
boskap
Posts: 21
Joined: Sun Jul 15, 2018 4:00 pm

browse folder function problem

Post by boskap » Sun Jul 22, 2018 5:12 am

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

User avatar
jvierra
Posts: 13623
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: browse folder function problem

Post by jvierra » Sun Jul 22, 2018 6:21 am

The following is a safe way to join multiple path segments.

$global:DestPath = [system.io.path]::Combine($Back_Rec_Path.'BACKUP',$Env:USERNAME)

boskap
Posts: 21
Joined: Sun Jul 15, 2018 4:00 pm

Re: browse folder function problem

Post by boskap » Sun Jul 22, 2018 12:53 pm

hi
thx

But can you explain what this line means
what means system.io.path

$global:DestPath = [system.io.path]::Combine($Back_Rec_Path.'BACKUP',$Env:USERNAME)

thx for your support

User avatar
jvierra
Posts: 13623
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: browse folder function problem

Post by jvierra » Sun Jul 22, 2018 1:59 pm


Locked