I am working on developing a Windows Form application in C#.
I have two different folder locations, one of which gets updated by Google File Stream (Google Drive software).
I need to clone this Google file Stream folder into my other folder on the local D drive, and update it while my Windows form is open.
I was thinking of comparing the differences between these two folders, then copying the differences from one folder into the next.
I am not sure how to do this, any help would be appreciated.
If your source folder is a normal windows folder (which is updated by google file stream, rather than a google filestream folder) you should be able to use the 'FileSystemWatcher' class. This class watches a folder for specified changes and raises events when they happen (which your application can then handle).
Here is an article I used when I needed to do something similar (watching a folder for changes) How to work with file system watcher in C#
In case the article goes offline, here is the summary lifted directly from it:
The following code snippet shows how the MonitorDirectory method would look like. This method would be used to monitor a particular directory and raise events whenever a change occurs. The directory path is passed as an argument to the method.
private static void MonitorDirectory(string path)
{
FileSystemWatcher fileSystemWatcher = new FileSystemWatcher();
fileSystemWatcher.Path = path;
fileSystemWatcher.Created += FileSystemWatcher_Created;
fileSystemWatcher.Renamed += FileSystemWatcher_Renamed;
fileSystemWatcher.Deleted += FileSystemWatcher_Deleted;
fileSystemWatcher.EnableRaisingEvents = true;
}
You'll want to substitute your own event handlers (or implement ones with the names above).
For additional bonus, you can also use the FileSystemWatcher's filter property to target specific file types.
Full documentation on Microsoft Docs