Delete Files in Directory Except Some Files

If you need to delete some files in directory, you can automize this. Also you can protect some files on that directory. We are using a little PHP Code for it.

PHP CODE:

<?php
// We write our subdirectories for deleting their content
$directories = array("./", "resim1", "resim2", "resim3", "resim4", "resim5");

for($a=0;$a=<count($directories);$a++)
{
    if ($source = opendir($directories[$a]))
 {
        while (false !== ($file = readdir($source)))
  {
            if ($file != "." && $file != ".." && substr($file ,-4) == ".jpg" && $file != "index.php")
   {
    $deleting_file = $directories[$a]."/".$file;
    if(unlink($deleting_file))
     echo($deleting_file." is deleted..");
    else
     echo("ERROR: ".$deleting_file." is <b>not</b> deleted..");
            }
        }
    }
 else
 {
  echo("ERROR: Not access with ".$directories[$a]);
 }
}
?>
Oyun