![]() ![]() ![]() # find the path to the desktop folder: $desktop = :: GetFolderPath ( 'Desktop' ) # specify the path to the folder you want to monitor: $Path = $desktop # specify which files you want to monitor $FileFilter = '*' # specify whether you want to monitor subfolders as well: $IncludeSubfolders = $true # specify the file or folder properties you want to monitor: $AttributeFilter = :: FileName, :: LastWrite # specify the type of changes you want to monitor: $ChangeTypes = :: Created, :: Deleted # specify the maximum time (in milliseconds) you want to wait for changes: $Timeout = 1000 # define a function that gets called for every change: function Invoke-SomeAction # subscribe your event handler to all event types that are # important to you. Whenever a change is detected, Invoke-SomeAction is called. File Watcher is an activity that watches a directory for specific file events like create, delete, exist, update, and rename, allowing the developer to. This is straight-forward: the script below monitors your desktop and all of its subfolders for new files and for deletion of files. However, responding to events is not trivial in a single-threaded environment like PowerShell. When specific changes are detected a notification, can be sent to and endpoint via an API request, an action (copy, move, delete) can be performed, or a command executed. This way, you cannot miss change events because the FileSystemWatcher is constantly monitoring. File Watcher is an application designed to monitor folders and files on the local system. Instead, whenever a change occurs, an event is fired, and your script can respond to the events.
0 Comments
Leave a Reply. |