Scripting Question

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.
User avatar
jvierra
Posts: 13681
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Scripting Question

Post by jvierra » Wed Oct 03, 2018 1:56 pm

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
Joined: Sun Jul 15, 2018 4:00 pm

Re: Scripting Question

Post by boskap » Thu Oct 04, 2018 2:57 am

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

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

Re: Scripting Question

Post by jvierra » Thu Oct 04, 2018 3:22 am

Please run in debugger to find your issue. We cannot see tour system.

Locked