lill87 Posted May 12, 2007 Share Posted May 12, 2007 Is there some way using unlink or some other code to delete ALL files in the specified folder? Thanks for your answers! Quote Link to comment https://forums.phpfreaks.com/topic/51114-solved-deletion/ Share on other sites More sharing options...
MadTechie Posted May 12, 2007 Share Posted May 12, 2007 nope your have to delete each file then remove the directory <?php /** * rm() -- Vigorously erase files and directories. * * @param $fileglob mixed If string, must be a file name (foo.txt), glob pattern (*.txt), or directory name. * If array, must be an array of file names, glob patterns, or directories. */ function rm($fileglob) { if (is_string($fileglob)) { if (is_file($fileglob)) { return unlink($fileglob); } else if (is_dir($fileglob)) { $ok = rm("$fileglob/*"); if (! $ok) { return false; } return rmdir($fileglob); } else { $matching = glob($fileglob); if ($matching === false) { trigger_error(sprintf('No files match supplied glob %s', $fileglob), E_USER_WARNING); return false; } $rcs = array_map('rm', $matching); if (in_array(false, $rcs)) { return false; } } } else if (is_array($fileglob)) { $rcs = array_map('rm', $fileglob); if (in_array(false, $rcs)) { return false; } } else { trigger_error('Param #1 must be filename or glob pattern, or array of filenames or glob patterns', E_USER_ERROR); return false; } return true; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/51114-solved-deletion/#findComment-251621 Share on other sites More sharing options...
lill87 Posted May 12, 2007 Author Share Posted May 12, 2007 ok thanks! Quote Link to comment https://forums.phpfreaks.com/topic/51114-solved-deletion/#findComment-251622 Share on other sites More sharing options...
lill87 Posted May 12, 2007 Author Share Posted May 12, 2007 I came up with my own little code $result = mysql_query("SELECT * FROM users") or die("Error: Table does not exist!"); while($row = mysql_fetch_array( $result )) { $deletefirst = "players/".$row['username'].".php"; unlink($deletefirst); } So, Solved! Quote Link to comment https://forums.phpfreaks.com/topic/51114-solved-deletion/#findComment-251629 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.