![如何使用命令行从 iPhone 复制文件?](https://linux22.com/image/1587149/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%E5%91%BD%E4%BB%A4%E8%A1%8C%E4%BB%8E%20iPhone%20%E5%A4%8D%E5%88%B6%E6%96%87%E4%BB%B6%EF%BC%9F.png)
答案1
如果你想避免使用第三方软件,电源外壳可以使用shell.application
com对象访问虚拟文件夹和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 <---|
参考: