filewatcher to unzip when event (.zip) is detected - Microsoft Community


hello,

i new powershell (basically new programming), need help.

i want create below flow using powershell:

watch file in foldera (.zip) --> move file folderb (.zip)--> unzip moved file in folderc (with same name) --> , trigger batch file inside folderc.

my powershell script below: (gathered lot of internet sources)

### set folder watch + files watch + subfolders yes/no
    $watcher = new-object system.io.filesystemwatcher
    $watcher.path = "d:\localdata\username\desktop\foldera"
    $watcher.filter = "*.zip*"
    $watcher.includesubdirectories = $true
    $watcher.enableraisingevents = $true
    $destination = "d:\localdata\username\desktop\folderb"

### function unzip moved item
add-type -assemblyname system.io.compression.filesystem
function global:unzip
{
    param([string]$zipfile, [string]$outpath)
    [system.io.compression.zipfile]::extracttodirectory($zipfile, $outpath)
}

### define actions after event detected
    $action = { $path = $event.sourceeventargs.fullpath
                $changetype = $event.sourceeventargs.changetype
                $logline = "$(get-date), $changetype, $path"
                add-content -path "d:\localdata\username\desktop\logs\logs1.log" -value $logline
                ### moves detected event (any new created .zip)
                move-item $path $destination
               unzip $event "d:\localdata\username\desktop\folderb\folderc" (how give input $path ?)
              }

### decide events should watched
    register-objectevent $watcher "created" -action $action
    #register-objectevent $watcher "changed" -action $action
    #register-objectevent $watcher "deleted" -action $action
    register-objectevent $watcher "renamed" -action $action
    while ($true) {sleep 5}

any on push interest in programming/scripting.

sud.

ok.! got answer stackoverflow

thank you.



Windows / Windows 7 / Programs



Comments

Popular posts from this blog

ClipUp.exe 100% CPU at boot only - Microsoft Community

Error 8233 Microsoft Windows security -spp - Microsoft Community