Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7795141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:59:01+00:00 2026-06-01T22:59:01+00:00

I found this script that deletes files from a specific extension from a specific

  • 0

I found this script that deletes files from a specific extension from a specific folder i would like to know how can i make it to search files that end with instead of extension lets say “-75×60.jpg” please help me out. tx

File: file_del.class.php

class fileDel
{

     var $extension;

   /** 
   *   @purpose: Sets path and extension
   *   @params : path, file extension to delete
   *   @return none
   */

   function fileDel($extension)
   {
      $this->extension = $extension;    
   }//End of function

   /** 
   *   @purpose: Recursively deleting files
   *   @params : path to execute
   *   @return : none
   */

   function delDirFiles ($path)
   {
      $dir = opendir ($path);

      while ($file = readdir ($dir)) 
      {
         if (($file == ".") or ($file == ".."))
         {
            continue;
         }                

             if (filetype ("$path/$file") == "dir")
             {              
            $this->delDirFiles("$path/$file");
         }                
         //whether file of desired extension is found
                 elseif($this->findExtension($file)==$this->extension)
                 {                    
            if(@unlink ("$path/$file"))
            {
               echo "$path/$file >> <b>Deleted</b><br>";
            }   
         }                   

      } //End of while
      closedir($dir);

   }//End of function

   /** 
   *   @purpose: Finding extension of a file
   *   @params : filename
   *   @return : extension
   */
   function findExtension($file)
   {

      return array_pop(explode(".",$file));

   }//End of function

} //End of class

File: test.php

require_once "file_del.class.php";

$path = "/your/desired/path/to/delete_from";
$ext  = "desired_ext";

$delObj = new fileDel($ext);

$delObj->delDirFiles($path);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T22:59:03+00:00Added an answer on June 1, 2026 at 10:59 pm

    Try this:

    <?php
    class fileDel {
        var $fileEndsWith;
    
        function fileDel($fileEndsWith) {
            $this->fileEndsWith = $fileEndsWith;
        }
    
        function delDirFiles ($path) {
            $dir = opendir ($path);
    
            while ($file = readdir ($dir)) {
                if (($file == ".") or ($file == "..")) {
                    continue;
                }
    
                if (filetype("$path/$file") == "dir") {
                    $this->delDirFiles("$path/$file");
                }
                elseif($this->findFileEndsWith($file)==$this->fileEndsWith) {                    
                    if(@unlink ("$path/$file")) {
                        echo "$path/$file >> <b>Deleted</b><br>";
                    }
                }
            }
            closedir($dir);
        }
    
        function findFileEndsWith($file) {
            $length = strlen( $this->fileEndsWith );
            return substr( $file, -$length, $length );
        }
    }
    
    require_once "file_del.class.php";
    
    $path = "/your/desired/path/to/delete_from";
    $ext  = "desired_file_end_str";
    
    $delObj = new fileDel($ext);
    
    $delObj->delDirFiles($path);
    ?>
    

    Hope it helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have found a useful shell script that shows all files in a directory
I found this script: <script language=Javascript TYPE=text/javascript> var container = document.getElementById('dl'); var seconds =
Hi i'm building a webapp. To remove the onclick delay i found this script
I've found this login script and I'm trying to implement it into my website
I found this RGB to HSL script over at http://www.mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript . I can't find
I have a question about this script I found and used. It works but
I wanted to use groovy for a little ftp script and found this post
found this regex: insert every 10 characters: $text = preg_replace(|(.{10})|u, \${1}. , $text); can
I am new to Python and would like to know if someone would kindly
I've done a bit of searching on this. Found plenty of scripts that counted

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.