特定のフォルダから特定の拡張子のファイルを削除するこのスクリプトが見つかりました。拡張子ではなく末尾にあるファイルを検索するにはどうすればよいですか?-75x60 .jpg "私を助けてください。 TX拡張子の代わりに "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