Created
March 1, 2019 16:56
-
-
Save emnh/98480e2020c222365925743327d9be3b to your computer and use it in GitHub Desktop.
Android (Huawei P10 Lite) File Copier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://blogs.technet.com/b/heyscriptingguy/archive/2013/04/26/use-powershell-to-work-with-windows-explorer.aspx | |
$o = New-Object -com Shell.Application | |
$folder = $o.NameSpace(0x11) | |
# https://msdn.microsoft.com/en-us/library/windows/desktop/bb774096(v=vs.85).aspx | |
# ShellSpecialFolderConstants.ssfDRIVES == 0x11 | |
$items = $folder.Items() | |
for ($i= 0; $i -lt $items.Count; $i++) { | |
write-output ([string]$i + ": " + $items.Item($i).Name) | |
} | |
#$choice = Read-Host "Make your choice" | |
$choice = 7 | |
$android = $items.Item([int]$choice) | |
$root = $android.GetFolder() | |
# FolderItem versus FolderItems | |
#$maxdepth = Read-Host "Max depth" | |
$maxdepth = 100 | |
Function Write-Items($item, $depth, $maxdepth) { | |
#if ($depth -ge $maxdepth) { | |
# return; | |
#} | |
if ($item.Title -eq "cache") { | |
return; | |
} | |
if ($item.Title -eq "logs") { | |
return; | |
} | |
$indent = "" | |
for ($i = 0; $i -lt $depth; $i++) { | |
$indent += " "; | |
} | |
#write-output ($indent + "Name: " + $item.name) | |
if ($item.Title) { | |
$hash = @{ | |
Name = $item.Title | |
Size = $null #$item.ParentFolder.GetDetailsOf($item, 2) | |
Modified = $null #$item.ParentFolder.GetDetailsOf($item, 3) | |
Parent = $item.ParentFolder.Title | |
Level = $depth | |
} | |
$Object = New-Object PSObject -Property $hash | |
#write-output $object | |
#Write-Output $item | |
} else { | |
$hash = @{ | |
Name = $item.Name | |
Size = $item.Parent.GetDetailsOf($item, 2) | |
Modified = $item.Parent.GetDetailsOf($item, 3) | |
Parent = $item.Parent.Title | |
Level = $depth | |
} | |
$Object = New-Object PSObject -Property $hash | |
#Write-Output $object | |
#Write-Output $item | |
$parent = $item.Parent | |
$path = "" | |
while ($parent) { | |
#Write-Output $parent.Title | |
#Write-Output $path | |
$path = Join-Path $parent.Title $path | |
$parent = $parent.Parent | |
} | |
$path = Join-Path "E:\testnat\output" $path | |
if (!(Test-Path $path)) { | |
New-Item -ItemType Directory $path | |
#Write-Output "Creating $path" | |
} else { | |
#Write-Output "Skipping $path" | |
} | |
$fullpath = Join-Path $path $item.Name | |
write-output $fullpath #"Copying " $item.Name " to " $path | |
if (!(Test-Path $fullpath)) { | |
$CopyFlags = 16 | |
$destination = $path | |
$objShell = New-Object -ComObject 'Shell.Application' | |
$objFolder = $objShell.NameSpace((gi $destination).FullName) | |
$objFolder.CopyHere($item,$CopyFlags.ToString('{0:x}')) | |
} | |
} | |
if ($item.Count -gt 0) { | |
# $item is a folder with its own items | |
for ($i = 0; $i -lt $item.Count) { | |
$item2 = $item.item($i) | |
Write-Items $item2 $depth+1 $maxdepth | |
} | |
} | |
else { | |
if ($item.Items) { | |
$items = $item.Items() | |
if ($items.Count -gt 0) { | |
foreach ($i in $items) { | |
if ($i.IsFolder) { | |
$folder = $i.GetFolder() | |
Write-Items $folder ($depth+1) $maxdepth | |
} | |
else { | |
Write-Items $i ($depth+1) $maxdepth | |
} | |
} | |
} | |
} | |
else { | |
# .Count == 0 and no Items present | |
# we don't need to do anything further here | |
} | |
} | |
} | |
#Write-Items $root 0 $maxdepth | Out-GridView | |
Write-Items $root 0 1000 | |
#$item.CopyHere("E:\test\test.mp3") | |
#Copy-ItemUsingExplorer $item.Path "e:\testnat\test.mp3" 0 | |
#Copy-ShellItem $item -Destination E:\testnat\ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment