You can track file changes on a disk or local network device with the aid of File System Watcher. Console applications that respond to modifications based on the files that are copied, erased, altered, or generated can use it.
I set up an example to watch PDF files in the OneDrive default user folder. Make a console application with.
dotnet new console --name myConsoleApp
Add the code below to Program.cs, and you will start monitoring the OneDrive folder on Windows machines.
Inside the events, you can do whatever you need with the files.
To prevent the app from starting more than once, create a Mutex to prevent several instances from running at the same time. You need to create a unique name for your application, replacing UniqueApplicationName.
You can hide the console screen to avoid the use of terminating the application, and add the code below to the top of the Program.cs.
You can create logs or process files that have been modified, created, deleted, or changed; it's up to you and your requirements to monitor file changes on the hard drive.
Use this resource wisely.
0 comments:
Post a Comment