Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Iristyle/5986433 to your computer and use it in GitHub Desktop.
Save Iristyle/5986433 to your computer and use it in GitHub Desktop.
# 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'
}
}
@Iristyle
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment