我發現這個腳本,從特定擴展名從特定文件夾中刪除文件我想知道如何使它能夠搜索文件,而不是擴展結束讓我們說「-75x60 .jpg「請幫助我。 TX搜索「結尾」而不是擴展
文件: file_del.class.php
class fileDel
{
var $extension;
/**
* @purpose: Sets path and extension
* @params : path, file extension to delete
* @return none
*/
function fileDel($extension)
{
$this->extension = $extension;
}//End of function
/**
* @purpose: Recursively deleting files
* @params : path to execute
* @return : none
*/
function delDirFiles ($path)
{
$dir = opendir ($path);
while ($file = readdir ($dir))
{
if (($file == ".") or ($file == ".."))
{
continue;
}
if (filetype ("$path/$file") == "dir")
{
$this->delDirFiles("$path/$file");
}
//whether file of desired extension is found
elseif($this->findExtension($file)==$this->extension)
{
if(@unlink ("$path/$file"))
{
echo "$path/$file >> <b>Deleted</b><br>";
}
}
} //End of while
closedir($dir);
}//End of function
/**
* @purpose: Finding extension of a file
* @params : filename
* @return : extension
*/
function findExtension($file)
{
return array_pop(explode(".",$file));
}//End of function
} //End of class
文件: test.php的
require_once "file_del.class.php";
$path = "/your/desired/path/to/delete_from";
$ext = "desired_ext";
$delObj = new fileDel($ext);
$delObj->delDirFiles($path);
看一看http://php.net/glob :-) – YMMD 2012-04-10 14:40:37
只是一個提示:不要使用該腳本,看起來非常脆弱,因爲這是關於刪除文件,我會說:用c處理是,不要把自己打到腳上。 – hakre 2012-04-10 14:42:00