Advertisement
mobilefish

Untitled

Oct 1st, 2022
904
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Get-EventSubscriber -SourceIdentifier "FileCreated" | Unregister-Event
  2. $global:sourceFolder = 'C:\sourceFolder'
  3. $global:destinationFolder = 'F:\destinationFolder'
  4. $filter = '*.*'
  5. $fsw = New-Object IO.FileSystemWatcher $sourceFolder, $filter
  6. $fsw.IncludeSubdirectories = $true
  7.            
  8. $fsw.NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'
  9. $onCreated = Register-ObjectEvent $fsw Created -SourceIdentifier FileCreated -Action {
  10.     $name = $Event.SourceEventArgs.Name
  11.     $path = $Event.SourceEventArgs.FullPath
  12. #    Write-Host "The file '$name' '$path'"
  13.     Write-Host " source '$path'"
  14.     Write-Host "'destination $destinationFolder'"
  15.     Start-Sleep -s 20
  16.     Move-Item -force $sourceFolder/*.* $destinationFolder
  17. #    cmd.exe /c 'test.bat'
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement