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.
unlink() multiple files
Moderator: General Moderators
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);
}
?>- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact: