Last active
June 19, 2016 08:46
-
-
Save GWuk/0fb500b02591e173a4659dded5bf18b0 to your computer and use it in GitHub Desktop.
copy new image+video files from Fuji X-T10 to local staging directories, either from mtp or sd card
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
# for direct start: exec powershell command "Set-ExecutionPolicy Unrestricted" once in elevated prompt | |
# store variables used before to clean up afterwards (https://blogs.technet.microsoft.com/heyscriptingguy/2011/08/21/clean-up-your-powershell-environment-by-tracking-variable-use/) | |
$startupVariables="" | |
new-variable -force -name startupVariables -value ( Get-Variable | % { $_.Name } ) | |
# https://blogs.technet.microsoft.com/jamesone/2009/09/23/on-scanners-cameras-and-their-usb-modes-and-lifting-the-lid-on-how-they-can-be-scripted/ | |
#$WIAdialog = New-Object -ComObject "WIA.CommonDialog" | |
#$Device = $WIAdialog.ShowSelectDevice() | |
#$Device.Properties | sort name | format-table –autosize name,value | |
#$img = $device.items.item(2) | |
#$img.Properties | sort name | format-table propertyID,name,value,type,isreadonly –autosize | |
#$img.Transfer().SaveFile('c:\temp\1\c.jpg') | |
# | |
#foreach ($i in $device.items) { $i.Properties | sort name | format-table propertyID,name,value,type,isreadonly –autosize } | |
#foreach ($i in $device.items) { if ($i.Properties.Item('Filename extension').Value -eq "JPG") { $i.Properties.Item('Item Name').Value } } | |
# no movies :-( | |
#foreach ($i in $device.items) { if ($i.Properties.Item('Filename extension').Value -eq "MOV") { $i.Properties.Item('Item Name').Value } } | |
# staging area | |
$destname = 'C:\Temp\FujiStage\' | |
$maxfile = "$destname\max.txt" | |
# read state file | |
[int]$max = Get-Content $maxfile | |
echo "current max: $max" | |
# init explorer object and staging | |
$o = New-Object -com Shell.Application | |
$dest = $o.NameSpace($destname) | |
# get constant for namespace from ShellSpecialFolderConstants enumeration (https://msdn.microsoft.com/en-us/library/windows/desktop/bb774096%28v=vs.85%29.aspx), should be 17 (=0x11) | |
$MyComputer = [int]($o.gettype().assembly.getexportedtypes() | where-object {$_.IsEnum -and $_.name -eq 'SpecialFolder'})::MyComputer | |
# search MTP and SD card | |
foreach ($i in $o.NameSpace($MyComputer).Items()) { | |
if ($i.Name -eq "X-T10") { | |
$srcdir = $i.GetFolder.Items().item(0).GetFolder.Items().item(0).GetFolder.Items().item(0).GetFolder.Items() | |
break | |
} | |
if ($i.GetFolder.Items().item(0).Name -eq "DCIM" -and $i.GetFolder.Items().item(0).GetFolder.Items().item(0).Name.EndsWith('_FUJI') ) { | |
$srcdir = $i.GetFolder.Items().item(0).GetFolder.Items().item($i.GetFolder.Items().item(0).GetFolder.Items().Count - 1).GetFolder.Items() | |
$eject = $i | |
break | |
} | |
} | |
# copy all jpg and mov to staging and raise max | |
$newmax=$max | |
foreach ($i in $srcdir) { | |
if ($i.name.tolower().endswith('.jpg') -or $i.name.tolower().endswith('.mov')) { | |
[int]$n = $i.name -Replace '^DSCF(\d{4})\.(MOV|JPG)$', '$1' | |
if ($n -gt $max) { | |
$i.name | |
$dest.CopyHere($i) | |
if ($n -gt $newmax) { $newmax=$n } | |
} | |
} | |
} | |
echo " new max: $newmax" | |
# write to state file | |
$newmax | out-file -filepath $maxfile | |
# eject SD Card | |
if ($eject) { $eject.InvokeVerb('Eject') } | |
Write-Host 'Press any key to continue ...' | |
try { $dummy = [console]::ReadKey("NoEcho,IncludeKeyDown") } catch {} | |
# clean up variables | |
Get-Variable | Where-Object { $startupVariables -notcontains $_.Name } | % { try { Remove-Variable -Name "$($_.Name)" -Force -Scope "global" -ErrorAction Stop } catch {} } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment