Page 1 of 1

unlink() multiple files

Posted: Wed Jan 17, 2007 7:52 am
by dhrosti
im having trouble finding anything about this on google, so i hope you guys can help.

I need to find a way to use unlink() or something similar to delete all files that start with a certain string.

Not sure how to go about this.

Posted: Wed Jan 17, 2007 8:15 am
by Grim...
Something like this:

Code: Select all

<?php
$dir = $_SERVER["DOCUMENT_ROOT"]."/folder/";
if ($dh = opendir($dir)) 
{
    while (($file = readdir($dh)) !== false) 
    {
        if (substr($file, 0, 3) == "xxx")
        {
	    unlink($file);
        }
    }
    closedir($dh);
}
?>

Posted: Wed Jan 17, 2007 10:34 am
by John Cartwright
glob() and unlink() combo can easily accomplish this