Created
July 12, 2013 17:59
-
-
Save Iristyle/5986433 to your computer and use it in GitHub Desktop.
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
# TODO: replace this hard-coded path with the path on disk where dngs are stored for current trip | |
$tripLocalPath = 'C:\Users\Ethan\Pictures\Curacao 2013' | |
$tripLocalFilter = '*.dng' | |
$memoryCardPath = 'd:\\' | |
$memoryCardFilter = '*.orf' | |
$names = dir $tripLocalPath -Recurse -Include $tripLocalFilter | | |
Select -ExpandProperty BaseName | | |
Sort-Object | |
$memoryCardFiles = Get-ChildItem $memoryCardPath -Filter $memoryCardFilter -Recurse | |
$keepers = $memoryCardFiles | ? { $names -icontains $_.BaseName } | |
$toDelete = $memoryCardFiles | ? { $names -inotcontains $_.BaseName } | |
if ($names.Length -ne $keepers.Length) | |
{ | |
throw "Memory card keeper count does not match local keeper count! Disk: [$($names.Length)] / Card: [$($keepers.Length)]" | |
} | |
if ($memoryCardFiles.Length -ne ($names.Length + $toDelete.Length)) | |
{ | |
throw "Memory card file count [$($memoryCardFiles.Length)] does not match on disk keepers [$($names.Length)] + files to delete [$($toDelete.Length)] count!" | |
} | |
switch (Read-Host -Prompt "Really delete [$($toDelete.Length)] files from $memoryCardPath? [y/n]") | |
{ | |
'y' | |
{ | |
$toDelete | | |
% { | |
Write-Host "Deleting $($_.FullName)!" | |
$_ | Remove-Item | |
} | |
} | |
default | |
{ | |
Write-Host 'Not deleting files' | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Has some simple checks to ensure you don't delete stuff when things don't match up... Add a
-WhatIf
on line 34 to see the list of files to be deleted.