Thursday, August 28, 2008

Remove files from a folder dynamically using PHP


/* Your file path to remove the files */
$path_file = "/www/htdocs/evergreenphp/samplefile";
$execept_file = "imageshuffle.xml";

/* Caling function : Removing the files */
Remove_unwanted($path_file, $execept_file);

/* Function Definition : Remove unwanted files */
function Remove_unwanted($path, $execept_file){
$path_dir = opendir($path);
while (($files = readdir($path_dir)) !== false) {

$check_file = explode(".", $files);

/*
Here Deletion based on
1. File type is a XML
2. File name not equal to $execept_file
*/

if (($check_file[1] == "xml") && ($files != $execept_file))
{
@unlink($path."/".$files);
}
}
}

?>

1 comment:

Narasing said...

This concept is very useful one

Popular Posts