Deleting all files with a certain prefix

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • laredotornado@zipmail.com

    Deleting all files with a certain prefix

    Hi,

    I'm using php 4.4.4. Given a particular directory, I want to delete
    all the files that begin with the variable "$prefix". What is the
    simplest way to do this?

    Thanks ,- Dave

  • Rik

    #2
    Re: Deleting all files with a certain prefix

    On Wed, 18 Jul 2007 18:42:47 +0200, laredotornado@z ipmail.com
    <laredotornado@ zipmail.comwrot e:
    I'm using php 4.4.4. Given a particular directory, I want to delete
    all the files that begin with the variable "$prefix". What is the
    simplest way to do this?
    $dir = '/path/to/directory';
    $prefix = 'foo';
    chdir($dir);
    $matches = glob($prefix.'* ',GLOB_MARK);
    if(is_array($ma tches) && !empty($matches )){
    foreach($matche s as $match){
    if(is_file($dir .$match) unlink($dir.$ma tch);
    }
    }


    --
    Rik Wasmus

    Comment

    Working...