如何使用命令列從 iPhone 複製檔案?

如何使用命令列從 iPhone 複製檔案?

我想使用命令列存取 iPhone 上的文件,而不是使用 windows Ctrl+ C, Ctrl+V將所有文件複製到我的 PC。

我查看了是否可以將“這台電腦”或任何其他行映射為網路驅動器,但我找不到如何映射。

如下所示,我打算使用命令列(很可能是 DOS 風格的命令提示字元)複製 iPhone 資料夾。

我手機上的這台電腦

答案1

如果您想避免使用第三方軟體,電源外殼可以使用shell.applicationcom物件存取虛擬資料夾和MTP設備。這是一個簡單的複製腳本:

$pcDestinationPath = 'C:\Wherever\You\Want'
$phoneRelativePath = 'Internal Storage\DCIM'

$shell  = New-Object -com shell.application

$PhoneFolder = ($shell.NameSpace("shell:MyComputerFolder").Items() | where Type -match 'Mobile Phone|Portable Device').GetFolder

### To access a subfolder, you have to "walk" its path

$SourceFolder = $phoneRelativePath.Split('\') |
ForEach-Object -Begin {
    $comFolder = $PhoneFolder
} -Process {
    Try
    {
        $comFolder = ($comFolder.Items() | where {$_.IsFolder} | where Name -eq $_).GetFolder
    }
    Catch
    {
        Write-Error 'Failed to parse $DeviceFolderPath'
    }
} -End {
    $comFolder
}

### Get comFolder object for $pcDestinationPath

If ( ! (Test-Path $pcDestinationPath) )
{
    mkdir $pcDestinationPath -Force | out-null
}
$pcDestinationFolder = $shell.NameSpace($pcDestinationPath)
    
### Option 1: Copy $SourceFolder as a single item

$pcDestinationFolder.CopyHere($SourceFolder.Self)

### Option 2: Copy *the contents of* $SourceFolder as a collection of items

$pcDestinationFolder.CopyHere($SourceFolder.Items())

### Option 3: Copy selected items from $SourceFolder individually

$SourceFolder.Items() | where {<Test-Expression(s)>} |
ForEach-Object {
    $pcDestinationFolder.CopyHere($_)
}  

### FolderItem properties available for testing:
###   - IsFolder
###   - IsLink
###   - ModifyDate
###   - Name
###   - Parent
###   - Path
###   - Size
###   - Type

每個目錄都有一個資料夾物件和一個資料夾項與其關聯的對象。它們可以透過.Self和屬性相互引用GetFolder

       |--------> Folder.Self ------->|
    Folder                         FolderItem
       |<--- FolderItem.GetFolder <---|

參考:

相關內容