Is there a way to check if a file path is within a Google Drive directory using C#?

I’m working on a Windows desktop app in C# that saves data in a custom file format. We’ve run into issues with file corruption when these files are synced through Google Drive. I’m looking for a way to prevent users from saving files to Google Drive locations.

The tricky part is that this needs to work offline. We can’t use Google Drive API or any online services. We need a method to figure out if the save path is in a Google Drive folder without an internet connection.

I’ve tried looking for the sync_config.db file, but no luck so far. It’s not in the expected location on my system.

Has anyone come up with a reliable way to identify Google Drive paths locally? Any tips or code examples would be super helpful. Thanks!

hey, i’ve dealt with similar issues. one trick i found is checking for the presence of a ‘.tmp.drivedownload’ file in the folder. google drive creates these when syncing. it’s not foolproof, but might help. also, look for folders named ‘Google Drive’ or paths containing ‘GoogleDrive’ as a quick check.

As someone who’s grappled with this exact problem, I can share a workaround that’s proven quite effective. Instead of trying to detect Google Drive folders, which can be tricky and unreliable, I’ve had success implementing a custom file system watcher.

Essentially, you set up a FileSystemWatcher to monitor the directory where your app saves files. When it detects changes, you can implement a short delay (say, 5-10 seconds) before allowing further writes. This gives Google Drive time to finish its sync operations, reducing the risk of file corruption.

Additionally, I’ve found it helpful to implement a basic file locking mechanism. Before writing to a file, attempt to open it with exclusive access. If you can’t, it might be in use by Google Drive’s sync process, so wait and retry.

These approaches won’t prevent saving to Google Drive, but they can significantly reduce corruption issues without needing to detect Drive folders specifically. It’s been a game-changer for my projects dealing with similar syncing problems.

I’ve encountered this issue before in enterprise environments. One reliable method I’ve found is to check for the presence of a hidden ‘.drivesync’ folder at the root of the Google Drive directory. This folder is typically created during the initial setup of Google Drive File Stream or Backup and Sync.

You could implement a recursive search function that starts from the target save path and moves up the directory tree, looking for this ‘.drivesync’ folder. If found, you can assume the path is within a Google Drive directory.

Keep in mind that this approach isn’t 100% foolproof, as users might manually modify their Google Drive setup. However, it’s been quite effective in my experience for offline detection without relying on external APIs.