How to detect when a file changes using UiPath Studio
In UiPath Studio you can use the File Changed Trigger to monitor for file changes within a folder. Using this activity you can monitor when a new file is created, deleted or renamed, but also when the contents of the file have changed.
To detect when the contents of a file change, we’ll need to configure the File Changed Trigger activity in the following way:
- Path – set this to the folder which you want to monitor
- FileName Filter – leave it empty if you want to monitor all the files in the folder, or specify a file name if you are interested in a particular file. Alternatively, you can use wildcards (
*
) to match groups of files by extension. - In the Properties panel:
- ChangeType – select Changed
- NotifyFilters – unselect FileName, and select LastWrite
The trigger will output a FileChangeTriggerArgs
object which has a FileChangeInfo property that can be used to get more details about the change that has occured.
The type FileChangeInfo
provides the following information:
- ChangeType: the type of change that occured (Created, Changed, Deleted or Renamed)
- FullPath: the absolute path to the file that was changed
- Name: the name of the file that was change
- OldFullPath: the absolute path of the file before it was renamed
- OldName: the file name before it was renamed
For a working example you can check out the WhenFileContentChanged in the automation-examples repository.