Page 1 of 1

how can i delete all files in a folder

Posted: Fri Jul 20, 2007 1:37 pm
by itsmani1
Hi
I want to delete all .html files in current directory using php code?
any solution?

thanks a lot.

Posted: Fri Jul 20, 2007 2:44 pm
by Oren
glob() and unlink() may be of interest.

Posted: Fri Jul 20, 2007 2:57 pm
by Benjamin
I would look at opendir() and readdir()

http://us2.php.net/manual/en/function.readdir.php

Posted: Fri Jul 20, 2007 3:27 pm
by toasty2
I would do something like this:

Code: Select all

$dir_handle = @opendir('path') or die('Cannot read the path.');
while ($file = readdir($dir_handle)) 
{
	if(is_file($file) and strpos($file,'.html'))
	{
		unlink($file);
	}
}
closedir($dir_handle);