Advertisement
Guest User

Untitled

a guest
Mar 5th, 2017
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #NB: will cause an infinite loop
  2.  
  3. $f = 'E:\fsw' #original folder to monitor
  4. $file1 = 'fws.txt' # filter to monitor with.
  5. $file2 = 'C:\file.txt' #file to copy over
  6.  
  7. $fsw = New-Object IO.FileSystemWatcher $f, $file1 -Property @{NotifyFilter = [IO.NotifyFilters]'FileName, LastWrite'}
  8. Register-ObjectEvent $fsw Changed -SourceIdentifier FileChanged -Action {
  9.   $name = $Event.SourceEventArgs.Name
  10.   $changeType = $Event.SourceEventArgs.ChangeType
  11.   $timeStamp = $Event.TimeGenerated
  12.   Copy-Item $file2 -destination $f\$file1 -force
  13. }
  14.  
  15. # launch the following to remove the event:
  16. # Unregister-Event FileChanged
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement