Skip to content

Instantly share code, notes, and snippets.

@andrejko
Last active August 29, 2015 14:03
Show Gist options
  • Save andrejko/b9aa27defcc510a49e13 to your computer and use it in GitHub Desktop.
Save andrejko/b9aa27defcc510a49e13 to your computer and use it in GitHub Desktop.
<?php
$path = 'D:\\photos\\';
$extToDelete = 'DNG';
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
foreach ($it as $item) {
if (!$item->isDir()) {
if ($item->getExtension() == $extToDelete) {
$baseName = $item->getBaseName("." . $extToDelete);
if (!file_exists($path . $it->getSubPath() . '\\' . $baseName . '.JPG')) {
unlink($path . $it->getSubPath() . '\\' . $item->getFileName());
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment