Jump to content

Deleting all the files in a directory


Nakor
 Share

Recommended Posts

I am looking for a way to delete all of the files in a directory, be it with wildcards or some sort of a function argument that I am not aware of. Any help will be greatly appreciated.

Link to comment
Share on other sites

<?php$dir = "";foreach (glob("$dir/*") as $filename) {   echo "$filename - size: " . filesize($filename) . " bytes" . "\n";   unlink($filename);}?>

I haven't tested it, this is what I came up with from searching on http://www.php.net but all you should have to do is set the directory and in theory it should work.

Link to comment
Share on other sites

Ah, yes that would work as well. I just ended up settling with

exec("rm -f *.*");

but now that I think about it, your solution would end up being better, as it is probably more platform independent.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...