You are here: Re: Deleting all files with a certain prefix « PHP Programming Language « IT news, forums, messages
Re: Deleting all files with a certain prefix

Posted by Rik on 07/18/07 17:26

On Wed, 18 Jul 2007 18:42:47 +0200, laredotornado@zipmail.com =

<laredotornado@zipmail.com> wrote:
> 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 =3D '/path/to/directory';
$prefix =3D 'foo';
chdir($dir);
$matches =3D glob($prefix.'*',GLOB_MARK);
if(is_array($matches) && !empty($matches)){
foreach($matches as $match){
if(is_file($dir.$match) unlink($dir.$match);
}
}


-- =

Rik Wasmus

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация