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