这里的Python存在同样的问题:How can I get the Dropbox folder location programmatically in Python?,或者这里是OSX:How to get the location of currently logined Dropbox folder
Powershell也是如此。我需要DropBox的路径来复制文件(构建软件,然后将其复制到dropbox以与团队共享)。
答案 0 :(得分:5)
此Dropbox帮助页面告诉我们该信息的存储位置,即用户AppData中的json文件:https://www.dropbox.com/help/4584
function GetDropBoxPathFromInfoJson
{
$DropboxPath = Get-Content "$ENV:LOCALAPPDATA\Dropbox\info.json" -ErrorAction Stop | ConvertFrom-Json | % 'personal' | % 'path'
return $DropboxPath
}
以上一行取自:https://www.powershellgallery.com/packages/Spizzi.Profile/1.0.0/Content/Functions%5CProfile%5CInstall-ProfileEnvironment.ps1 请注意,它不会检查您是否拥有Dropbox企业帐户,或者是否同时拥有这两个帐户。它只是使用个人的。
然后,您可以使用此基本Dropbox文件夹来构建最终路径,例如:
$targetPath = Join-Path -Path (GetDropBoxPathFromInfoJson) -ChildPath 'RootDropboxFolder\Subfolder1\Subfolder2'
if (-not (Test-Path -Path $targetPath)) { throw "Path '$targetPath' not found!" }
-
替代方法是使用host.db文件,如下页所示: http://bradinscoe.tumblr.com/post/75819881755/get-dropbox-path-in-powershell
$base64path = gc $env:appdata\Dropbox\host.db | select -index 1 # -index 1 is the 2nd line in the file
$dropboxPath = [System.Text.Encoding]::ASCII.GetString([System.Convert]::FromBase64String($base64path)) # convert from base64 to ascii