google-drive-api

How do I get the google drive location?


How can I programmatically get (possibly without using the SDK) the location where the google drive in installed.

I just need the name of the root directory so that I can open it inside my windows application.

Thanks.


Solution

  • I found this code to extract the information I need. I'm posting it in case someone can benefit from it. I use SQLite to extract the information from the sync_config.db file.

    String dbFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Google\\Drive\\sync_config.db");
    
    string csGdrive = @"Data Source=" + dbFilePath + ";Version=3;New=False;Compress=True;";
    
            try {
                using (var con = new SQLiteConnection(csGdrive)) {
                    con.Open();
                    using (var sqLitecmd = new SQLiteCommand(con)) {
                        //To retrieve the folder use the following command text
                        sqLitecmd.CommandText = "select * from data where entry_key='local_sync_root_path'";
    
                        using (var reader = sqLitecmd.ExecuteReader()) {
                            reader.Read();
                            //String retrieved is in the format "\\?\<path>" that's why I have used Substring function to extract the path alone.
                            destFolder = reader["data_value"].ToString().Substring(4);
                            Console.WriteLine("Google Drive Folder: " + destFolder);
                        }
                    }
                }
            }