Скрипт, удаляет из выбранной директории файлы, удовлетворяющие маске префикс.* , где префикс задается в коде.
Скачать: PhPh_Autodeleter_2011-02-08.zip (скачиваний: 722)
Код
<?php
## This was coded by Ph&Ph (http://web.finar.ru) This is a script for automatical delete exisiting files satisfying $prefix.*
## here is some config:
$dir = "./"; // directory to delete files from
$prefix = "core"; // to delete filename prefix
## here config finishes.
## -----------Do not modify anything below-----------
if (is_dir($dir)) {
$dh = opendir($dir); // opening directory...
while (false !== ($filename = readdir($dh))) { // reading directory
if ($filename != "." && $filename != ".." ) { // bypass parent and current dirs
$pref = current(explode(".", $filename)); // get extension
if ($pref == "$prefix") { // if file has properly extension, then proceed
$files[] = $filename; // add this file to array
}
}
}
if (!empty($files)){
foreach ($files as $deleted) {
echo ("deleting $dir$deleted<br>");
unlink("$dir$deleted");
echo "File <b>$deleted</b> was deleted<br>";
echo "<br>Operation completed successful.";
}
}
}
else {
echo "$dir is not correct path ";
}
?>
## This was coded by Ph&Ph (http://web.finar.ru) This is a script for automatical delete exisiting files satisfying $prefix.*
## here is some config:
$dir = "./"; // directory to delete files from
$prefix = "core"; // to delete filename prefix
## here config finishes.
## -----------Do not modify anything below-----------
if (is_dir($dir)) {
$dh = opendir($dir); // opening directory...
while (false !== ($filename = readdir($dh))) { // reading directory
if ($filename != "." && $filename != ".." ) { // bypass parent and current dirs
$pref = current(explode(".", $filename)); // get extension
if ($pref == "$prefix") { // if file has properly extension, then proceed
$files[] = $filename; // add this file to array
}
}
}
if (!empty($files)){
foreach ($files as $deleted) {
echo ("deleting $dir$deleted<br>");
unlink("$dir$deleted");
echo "File <b>$deleted</b> was deleted<br>";
echo "<br>Operation completed successful.";
}
}
}
else {
echo "$dir is not correct path ";
}
?>
ToDo
Если в обрабатываемой директории окажется директория, удовлетворяющая маске, скрипт выдаст ошибку php. Надо бы сделать проверку.
Оставить комментарий