You are here: Re: deleting all the files in a directory « PHP Programming Language « IT news, forums, messages
Re: deleting all the files in a directory

Posted by Mladen Gogala on 02/15/06 08:12

On Mon, 13 Feb 2006 22:47:26 +0100, Ewoud Dronkert wrote:

> You're potentially missing (symbolic) links and files larger than
> int-size. Better to check for '.' or '..' filenames. Clumsy, I know.

This will work better:

foreach (glob("/mydir/*") as $f) {
filetype($f)== 'file' ? unlink($f) : null;
}

If my coding style betrays using some other scripting languages
as well, I cannot help it. In some other scripting languages that
might have been coded like this:

foreach (glob "/mydir/*") {
unlink($_) if -f $_;
}

As I don't have "suffix if" in PHP, I came up with the ternary operator.
Note that I could have written '' instead of "null" and still have the
same effect. Of course, I cannot rewrite something like this:

map { unlink($_) if -f $_; } glob("/mydir/*");



--
http://www.mgogala.com

 

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

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