How to delete all files beginning with ... ?

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

    How to delete all files beginning with ... ?

    Hi, I'm using PHP 4. I would like to delete all files in my directory
    /mydir that match the regular expression

    /mydir/temp*

    What is the shortest way in which I can do this?

    Thanks, - Dave

  • Chris Hope

    #2
    Re: How to delete all files beginning with ... ?

    laredotornado@z ipmail.com wrote:
    [color=blue]
    > Hi, I'm using PHP 4. I would like to delete all files in my directory
    > /mydir that match the regular expression
    >
    > /mydir/temp*
    >
    > What is the shortest way in which I can do this?[/color]

    How about: exec('rm -f /mydir/temp*');

    --
    Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/

    Comment

    • Erwin Moller

      #3
      Re: How to delete all files beginning with ... ?

      Chris Hope wrote:
      [color=blue]
      > laredotornado@z ipmail.com wrote:
      >[color=green]
      >> Hi, I'm using PHP 4. I would like to delete all files in my directory
      >> /mydir that match the regular expression
      >>
      >> /mydir/temp*
      >>
      >> What is the shortest way in which I can do this?[/color]
      >
      > How about: exec('rm -f /mydir/temp*');
      >[/color]


      Or a more platform independent way:

      foreach (glob("temp*") as $filename) {
      unlink ($filename);
      }

      Regards,
      Erwin Moller

      Comment

      Working...