我发现这个脚本从特定文件夹中的特定扩展名中删除文件我想知道如何让它搜索以而不是扩展名结尾的文件让我们说“-75x60.jpg”请帮帮我。发送
文件: 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);