B4J Question Get path to Dropbox?

tsteward

Well-Known Member
Licensed User
Longtime User
Is there a way I can ask the computer for the path to dropbox local files?

My program reads some files stored on dropbox. each computer has a slightly different path to the local files. I need to programatically find it.
 

Daestrum

Expert
Licensed User
Longtime User
Not sure if it's similar but I use this code to get the onedrive files (I don't use dropbox)
B4X:
File.ListFiles("C:\Users\"&GetSystemProperty("user.name","") &"\OneDrive\Documents")

As its only the username that changes in the path.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use this code:

B4X:
Sub FindDropboxPath As String
   For Each s As String In Array("APPDATA", "LOCALAPPDATA")
     Dim folder As String = GetEnvironmentVariable(s, "")
     If folder = "" Then Continue
     If File.Exists(folder, "Dropbox\info.json") Then
       Dim parser As JSONParser
       parser.Initialize(File.ReadString(folder, "Dropbox\info.json"))
       Dim m As Map = parser.NextObject
       Dim key As String
       If m.ContainsKey("business") Then key = "business" Else key = "personal"
       m = m.Get(key)
       Return m.Get("path")
     End If
   Next
   Return ""
End Sub

It is based on the information provided here: https://www.dropbox.com/help/4584

I don't have dropbox installed here so I cannot test it.
 
Upvote 0
Top