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]);
 }
}
?>
Share and Enjoy:
  • StumbleUpon
  • Digg
  • TwitThis
  • FriendFeed
  • del.icio.us
  • MySpace
  • Technorati
  • Facebook
  • Google Bookmarks
  • Live

Enjoy this article?

Consider subscribing to our RSS feed!

Share us Facebook, FriendFeed, Digg

Liked by

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

No Comments

No comments yet.

Sorry, the comment form is closed at this time.