It is currently Sat Jan 23, 2021 7:40 am

All times are UTC + 1 hour

Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Get path of the Google Drive folder
PostPosted: Mon Dec 16, 2019 8:24 pm 

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3967
Location: Berlin, Germany

for some programs it is useful to know the location of the Google Drive folder on a given system.
(see also my tip "Get path of the Dropbox folder")

Unfortunately I have no opportunity to test this code under Mac OS. So I would highly appreciate it if someone else would do so. :-)

; Code successfully tested with Google Backup and Sync 3.47
; and
; [v] PB 5.71 LTS (x64)
; on
; [v] Windows 10 Pro, version 1903
; [ ] Mac OS

CompilerIf #PB_Compiler_IsMainFile

Procedure.s GoogleDriveFolder ()
   ; -- return the main folder used by "Google Backup and Sync" client,
   ;    with trailing path separator, or "" if not found
   ; after <>
   Protected.i db, i
   Protected dbFile$, query$, ret$=""
   CompilerSelect #PB_Compiler_OS
      CompilerCase #PB_OS_Windows
         dbFile$ = GetEnvironmentVariable("localappdata") + "\Google\Drive\user_default\sync_config.db"
      CompilerCase #PB_OS_MacOS
         ; after <>
         ; (not yet tested)
         dbFile$ = "~/Library/Application Support/Google/Drive/user_default/sync_config.db"
      CompilerCase #PB_OS_Linux
         CompilerError "Sorry, GoogleDriveFolder() is not supported on Linux"
         ; In contrast to Windows and OSX, for Linux there is no official
         ; "Google Backup and Sync" client. One proposed solution is to
         ; integrate Google Drive using Gnome Online Accounts, see e.g.
         ; <>.
         ; However, this does not work on my Linux Mint 19.2 (x64) system.
         ; There are several third party Linux programs for synchronisation
         ; with Google Drive. The name and location of the corresponding
         ; folder depends on the particular program, so it's not possible
         ; to provide a general solution here.
   db = OpenDatabase(#PB_Any, dbFile$, "", "", #PB_Database_SQLite)
   If db
      query$ = "SELECT * FROM data WHERE entry_key='local_sync_root_path'"
      If DatabaseQuery(db, query$)
         If NextDatabaseRow(db)
            i = DatabaseColumnIndex(db, "data_value")
            ret$ = GetDatabaseString(db, i)
            If FileSize(ret$) <> -2          ; If 'ret$' is not an existing folder
               ret$ = ""
   If Asc(ret$) <> '' And Right(ret$, 1) <> #PS$
      ret$ + #PS$
   ProcedureReturn Mid(ret$, 5)   ; discard leading "\\?\"

CompilerIf #PB_Compiler_IsMainFile
   ; -- Demo
   Define GoogleDrive$ = GoogleDriveFolder()
   Debug "Location of Google Drive folder:"
   If Asc(GoogleDrive$) <> ''
      Debug "'" + GoogleDrive$ + "'"
      Debug "not found"

Please excuse my flawed English. My native language is PureBasic.
RSBasic's backups

Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour

Who is online

Users browsing this forum: No registered users and 45 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye