Windows 如何在 Powershell 中获取 Dropbox 文件夹
How to get the Dropbox folder in Powershell in Windows
此处 Python 存在相同问题:How can I get the Dropbox folder location programmatically in Python?, or here for OSX:
在 Powershell 中也是如此。我需要 DropBox 的路径才能将文件复制到它(构建一个软件,然后将其复制到 Dropbox 以与团队共享)。
此 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
此处 Python 存在相同问题:How can I get the Dropbox folder location programmatically in Python?, or here for OSX:
在 Powershell 中也是如此。我需要 DropBox 的路径才能将文件复制到它(构建一个软件,然后将其复制到 Dropbox 以与团队共享)。
此 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