2016-09-18 183 views
0

我有一個使用PowerShell的學校項目,我決定創建一個腳本來從手機(僅適用於Android)備份音樂,圖片和視頻到PC連接USB。爲此,我實際使用的是亞行,這(我希望有可能)會自動下載。PowerShell和ADB:如何在手機上找到文件的路徑

目前我有:

foreach ($file in .\adb.exe shell ls -R | Where-Object {$_ -match ".mp3" -or $_ -match ".flac" -or $_ -match ".wav"}) 
{ 
    echo $file 
    .\adb.exe pull -p $cheminFile C:\Users\admin\Desktop\test 
} 

現在我需要的是我的手機上的文件的路徑,然後我就可以將它們與複製:

.\adb.exe pull -p $pathFile C:\Users\admin\Desktop\test 

如何我能找到路徑嗎?如果您有任何建議,我會很樂意應用它們!

謝謝!

+0

請問'$文件中的代碼。\ adb.exe殼找到。/'工作? (或'find /') – TessellatingHeckler

+0

錯誤我不明白代碼是什麼。是:$ pathFile = $文件在。\ adb.exe shell找到./?因爲「in」是意想不到的。 – FoxYou

+0

它代替了你的代碼中的'$ file in。\ adb shell ____'。命令'ls -R'是一個linux shell命令,用於僅使用名稱列出子文件夾中的文件。 'find。/'是一個linux shell命令,用它們的完整路徑列出子文件夾中的文件。 – TessellatingHeckler

回答

0

這是在爲我的作品

<# 
    This powershell script pulls from a USB cable connected android device files to a windows folder. 
    If the folder has files in subfolders they will also be copied to a similar subfolder to under the target folder 
    The script requires the Android Debug Bridge (adb) available on the windows computer (no installation required) 

    Adb Overview 
    https://developer.android.com/studio/command-line/adb.html 

    Get ADB files 
    Download: SDK Platform Tools Release 
    https://developer.android.com/studio/releases/platform-tools.html#download 

    ADB Driver Download 
    I required that driver for the Samsung S7 attached to Windows 7 -> Windows 10 had the driver by default 
    https://www.androidpit.de/adb-treiber-android-windows#windowstreiber 
    http://adbdriver.com/downloads/ 

    activate on the android device within the developer options "USB debugging" 

    connect the adroid device via USB 

    change the USB connection type to PTP 

    check within your android device by the property of a file the path to use 

#> 

$VerbosePreference = "SilentlyContinue" 
$ADBExe = "D:\Android-platform-tools\adb.exe" 

cls 
. $ADBExe devices 

function FN-PullAllFilesFromAnAndroidFolder(){ 
    param 
     ([Parameter(mandatory=$true)] [String] $AndroidSourceFolder, 
      [Parameter(mandatory=$true)] [String] $WindowsTargetFolder ) 

    if ($True){ 

     $FilesInAndroidFolder = . $ADBExe shell find "'$AndroidSourceFolder'" -type f 
     $FilesInAndroidFolder | Write-Verbose 

     if ($True) 
     { 
      ForEach ($SingleFileInAndroidFolder in $FilesInAndroidFolder) 
      { 
       #Replace known characters that are not deliverd correctly by the "adb shell find" query to windows 
       $FileFullPathCodePageFixed = $SingleFileInAndroidFolder.Replace('ä', "ä") 
       $FileFullPathCodePageFixed = $FileFullPathCodePageFixed.Replace('Ä', "Ä") 
       $FileFullPathCodePageFixed = $FileFullPathCodePageFixed.Replace('Ö', "Ö") 
       $FileFullPathCodePageFixed = $FileFullPathCodePageFixed.Replace('Ãœ', "Ü") 
       $FileFullPathCodePageFixed = $FileFullPathCodePageFixed.Replace('ö', "ö") 
       $FileFullPathCodePageFixed = $FileFullPathCodePageFixed.Replace('ü', "ü") 

       $RelativeFullPath = $FileFullPathCodePageFixed.Substring($AndroidSourceFolder.Length - 1, (($FileFullPathCodePageFixed.Length) - $AndroidSourceFolder.Length) + 1) 

       if (!(Test-Path -LiteralPath (Join-Path -Path $WindowsTargetFolder -ChildPath $RelativeFullPath))) 
       { 
        #Check if folder to copy to exists; if not create it 
        $TargetDirectoryWindows = Join-Path -Path $WindowsTargetFolder -ChildPath (Split-Path -LiteralPath $RelativeFullPath) 
        If (! (Test-Path -LiteralPath $TargetDirectoryWindows)){New-Item -Path $TargetDirectoryWindows -ItemType Directory | Out-Null} 

        #Pull files from android device 
        . $ADBExe pull $FileFullPathCodePageFixed $(Join-Path -Path $WindowsTargetFolder -ChildPath $RelativeFullPath) 

       } Else 
       { 
        "Already Backuped: $FileFullPathCodePageFixed" 
       } 
      } 
     } 
    } 
} 


FN-PullAllFilesFromAnAndroidFolder -AndroidSourceFolder "/storage/3333-3432/DCIM/CAMERA/" ` 
            -WindowsTargetFolder "D:\Data\Pictures\SamsungS7\" 
相關問題