workflows

This topic contains 5 replies, has 3 voices, and was last updated by  Yegor Lopatin 2 years, 10 months ago.

  • Author
    Posts
  • #19998

    Yegor Lopatin
    Participant

    Hello guys
    please tel me the truth, where is my fault
    I was trying to archive a few files simultaniously in such way

    (pre)
    #alias
    set-alias sz "$env:ProgramFiles\7-Zip\7z.exe"

    #archive source files to volumes 1GB and save 7zfiles to temp folder
    workflow Archive-Files {
    $folder =dir $sourceFolder
    # The files are processed in parallel.
    foreach -parallel ($file in $folder)
    {
    sequence {
    $Path=$file.FullName
    $fileName=$file.Name
    $basename=$file.Basename
    $zippedFileName="$basename"+".7z"
    $fullPathZippedFile=$tempZipFolder+$zippedFileName
    sz a $fullPathZippedFile $Path -v1000M
    }
    }
    }(/pre)

    and it hangs forever(( no error no results. nothing

    please help me

  • #20001

    Don Jones
    Keymaster

    The sz command is being run in an implicit InlineScript activity. It doesn't have access to any of the variables and is probably prompting for something.

  • #20004

    Yegor Lopatin
    Participant

    Dear Don

    Please advise what do I need to change to get results
    Do I need
    InlineScript{sz a $fullPathZippedFile $Path -v1000M}

    or do i need to use sz command without any $variable ?

    or alias was set out of workflow scope?
    Regards

  • #20008

    Yegor Lopatin
    Participant

    Thanks you for responses MSDN has shown me the root cause

    "
    Variables in InlineScript

    By default, the variables that are defined in a workflow are not visible to the commands in the InlineScript script block. To make workflow variables visible to the InlineScript, use the $Using scope modifier.
    The following example shows how to make the values of top-level workflow variables available to the commands in an inlineScript script block."

    Best regards
    Yegor

  • #20016

    Dave Wyatt
    Moderator

    I don't use workflows much, so I had to fiddle with this a bit. Here's what appears to work for me in testing. (I don't actually have 7-zip installed on this computer, so I just launched cmd.exe /c and echo'ed some text out to the .7z files as a test.)

    $sourceFolder = 'C:\Source'
    $tempZipFolder = 'C:\Source\Temp\'
    
    #archive source files to volumes 1GB and save 7zfiles to temp folder
    workflow Archive-Files {
        param (
            [string] $SourceFolder,
            [string] $ZipFolder
        )
    
        $folder = dir $SourceFolder
        # The files are processed in parallel.
        foreach -parallel ($file in $folder)
        {
            InlineScript {
                $Path=$using:file.FullName
                $fileName=$using:file.Name
                $basename=$using:file.Basename
                $zippedFileName="$basename"+".7z"
                $fullPathZippedFile= Join-Path $using:ZipFolder $zippedFileName
                & "$env:ProgramFiles\7-Zip\7z.exe" a $fullPathZippedFile $Path -v1000M
            }
        }
    }
    
    Archive-Files -SourceFolder $sourceFolder -ZipFolder $tempZipFolder
    
  • #20018

    Yegor Lopatin
    Participant

    $using: was my gap
    thanks a lot Dave
    Also I have found this info about scopes within workflows on MSDN site

    Thanks for your help

You must be logged in to reply to this topic.