-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMoveAllFromPhone.ps1
69 lines (61 loc) · 2.14 KB
/
MoveAllFromPhone.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# This file just uses the first part of Daiyan's script (see the MoveFromPhone.ps1 script in this repository),
# to build a list of the folder names, which it then iterates through, calling the main move script on each folder.
#
param([string]$phoneName,[string]$sourceFolder,[string]$targetFolder,[string]$filter='(.jpg)|(.mp4)$')
function Get-ShellProxy
{
if( -not $global:ShellProxy)
{
$global:ShellProxy = new-object -com Shell.Application
}
$global:ShellProxy
}
function Get-Phone
{
param($phoneName)
$shell = Get-ShellProxy
# 17 (0x11) = ssfDRIVES from the ShellSpecialFolderConstants (https://msdn.microsoft.com/en-us/library/windows/desktop/bb774096(v=vs.85).aspx)
# => "My Computer" — the virtual folder that contains everything on the local computer: storage devices, printers, and Control Panel.
# This folder can also contain mapped network drives.
$shellItem = $shell.NameSpace(17).self
$phone = $shellItem.GetFolder.items() | where { $_.name -eq $phoneName }
return $phone
}
function Get-SubFolder
{
param($parent,[string]$path)
$pathParts = @( $path.Split([system.io.path]::DirectorySeparatorChar) )
$current = $parent
foreach ($pathPart in $pathParts)
{
if ($current -and $pathPart)
{
$current = $current.GetFolder.items() | where { $_.Name -eq $pathPart }
}
}
return $current
}
$phoneFolderPath = $sourceFolder
$destinationFolderPath = $targetFolder
$phone = Get-Phone -phoneName $phoneName
$folder = Get-SubFolder -parent $phone -path $phoneFolderPath
$items = @( $folder.GetFolder.items() )
$totalItems = $items.count
if ($totalItems -gt 0) {
echo "Found $totalItems items."
} else {
echo "Zero items found in $phoneFolderPath."
exit
}
foreach ($item in $items) {
echo " "
$subfolder = $item.Name
$launchcmd = ("MoveFromPhone.ps1")
$launchargs = (-join( `
" -phoneName '",$phoneName,`
"' -sourceFolder '\",$phoneFolderPath,"\",$subfolder, `
"' -targetFolder '", $destinationFolderPath,"\",$subfolder, `
"' -filter '(.JPG)|(.MOV)|(.PNG)$'" `
))
powershell.exe "$launchcmd $launchargs"
}