Executing multiple commands in Powershell -
i creating hot folder. file names coming in hot folder end either *.pdf.tif (incorrect) or *.pdf.k.tif (correct). if file comes in using naming convention *.pdf.k.tif, want move destination folder. if file comes in using *.pdf.tif naming convention want rename *.pdf.k.tif naming convention , move destination folder. note source , destination folder same regardless of naming convention.
the script below works solve both things individually. if file named correctly, moves destination. if file named incorrectly, script renames correctly not move file after renamed.
how can make when file renamed, still moves?
$where_to_move_folder = "c:\users\jonsl\desktop\jobs-in" $createdaction = { $path = $event.sourceeventargs.fullpath $name = $event.sourceeventargs.name $changetype = $event.sourceeventargs.changetype $timestamp = $event.timegenerated dir $folder_to_watch *.tif | rename-item -newname { $_.name -replace ".pdf.tif",".pdf.k.tif"}; move-item -path $($folder_to_watch + "\" + $name) -destination $where_to_move_folder -force } $filter = '*.tif' $fsw = new-object io.filesystemwatcher $fsw.path = $folder_to_watch $fsw.filter = $filter $fsw.includesubdirectories = $true $fsw.notifyfilter = [io.notifyfilters]'filename, lastwrite' register-objectevent $fsw -eventname created -sourceidentifier filecreated -action $createdaction $fsw.enableraisingevents = $true
Comments
Post a Comment