특정 폴더에서 특정 확장명의 파일을 삭제하는이 스크립트를 발견했습니다. 어떻게 확장명 대신 끝나는 파일을 검색 할 수 있는지 알고 싶습니다. "-75x60 .jpg "제발 도와주세요. 텍사스확장명 대신 "end with"검색
파일 :이 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
:-) 그냥 팁을 살펴 유무 : 해당 스크립트를 사용하지 마십시오, 매우 깨지기 보이는이 파일을 삭제에 관한 한, 나는 말할 것이다 : c로 처리하라. 너는 발에 몸을 발라서 쏘지 않는다. – hakre