|
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]
|