Created
August 28, 2016 18:05
-
-
Save GWuk/234771efd485d43b5ddbdb294c4ee759 to your computer and use it in GitHub Desktop.
copy image and movie files from SD card to separate directories for jpg and raw (raf)
This file contains hidden or 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 } ) | |
| $destname = 'C:\Temp\FujiStage\' | |
| $destnameRAW = 'C:\Temp\FujiStageRAW\' | |
| $maxfile = "$destname\max.txt" | |
| # read state file | |
| [int]$max = Get-Content $maxfile | |
| $newmax=$max | |
| echo "current max: $max" | |
| # init explorer object and staging | |
| $o = New-Object -com Shell.Application | |
| $dest = $o.NameSpace($destname) | |
| $destRAW = $o.NameSpace($destnameRAW) | |
| # 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 SD card | |
| foreach ($drive in $o.NameSpace($MyComputer).Items()) { | |
| if ($drive.GetFolder.Items().item(0).Name -eq "DCIM" -and $drive.GetFolder.Items().item(0).GetFolder.Items().item(0).Name.EndsWith('_FUJI') ) { | |
| $eject = $drive | |
| # search directories | |
| #?? TODO: nur in xyz_FUJI suchen, wenn aus $max möglich | |
| foreach ($dir in $drive.GetFolder.Items().item(0).GetFolder.Items()) { | |
| $srcdir = $dir.GetFolder.Items() | |
| # copy all jpg and mov to staging, raf to staging raw and raise max | |
| foreach ($i in $srcdir) { | |
| if ($i.name.tolower().endswith('.jpg') -or $i.name.tolower().endswith('.mov') -or $i.name.tolower().endswith('.raf')) { | |
| [int]$n = $i.name -Replace '^DSCF(\d{4})\.(MOV|JPG|RAF)$', '$1' | |
| if ($n -gt $max) { | |
| $i.name | |
| if ($i.name.tolower().endswith('.jpg') -or $i.name.tolower().endswith('.mov')) { | |
| $dest.CopyHere($i) | |
| } elseif ($i.name.tolower().endswith('.raf')) { | |
| $destRAW.CopyHere($i) | |
| } | |
| if ($n -gt $newmax) { $newmax=$n } | |
| } | |
| } | |
| } | |
| } | |
| break | |
| } | |
| } | |
| echo " new max: $newmax" | |
| # write to state file | |
| $newmax | out-file -filepath $maxfile | |
| # eject SD Card | |
| $doEject = Read-Host "Eject SD? (y/n)" | |
| if ($doEject -eq 'y' -and $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