Scripting Question

Ask your 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.
This topic is 5 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Scripting Question

Post by jvierra »

The best I can do is this:

Code: Select all

$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
        }
    }
}
I recommend running your code with the debugger to verify that you are getting the correct values. I see no way with this minimal example to determine what is causing your issue.

If "Test-Path" fails you are doing nothing. You need to do something when the path does not exist.
boskap
Posts: 21
Last visit: Sun Oct 21, 2018 4:24 am

Re: Scripting Question

Post by boskap »

ok but why it works with powershell v5
it creates the folder when it not exists

it only should create the folde if it not exists
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Scripting Question

Post by jvierra »

Please run in debugger to find your issue. We cannot see tour system.
This topic is 5 years and 5 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked