簡體   English   中英

如何在Windows中的Powershell中獲取Dropbox文件夾

[英]How to get the Dropbox folder in Powershell in Windows

這里的Python存在相同的問題: 如何在Python中以編程方式獲取Dropbox文件夾的位置? ,或在OSX上查看: 如何獲取當前登錄的Dropbox文件夾的位置

在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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM