php批量删除指定文件夹中指定后缀名文件

作者:袖梨 2022-06-24

直接上代码:

下面的例子我们是以删除指定目录的html为例子哦,如果你要其它文件我们只要把html改成你自己要删除的后缀名就可以了。

 代码如下 复制代码
$lanmu = array("action","tiyu","yizhi","sheji","gaoxiao","maoxian","qipai","celue","minjie","xiuxian","ertong","jingying","webgame");
foreach($lanmu as $v2){
    $mstdel[] =glob(getcwd().DIRECTORY_SEPARATOR.$v2.DIRECTORY_SEPARATOR.'[1-9]*.html');
}
 
//var_dump($mstdel);
 
//var_dump(count($mstdel));
$i=0;
foreach($mstdel as $val){
    foreach($val as $val2){
        //echo $val2."
";
        if(unlink($val2)) $i++;
        //$countval2[] = $val2;
    }
}
 
echo 'del success: '.$i;
 
//echo count($countval2);
//var_dump(glob(getcwd().DIRECTORY_SEPARATOR.'sheji'.DIRECTORY_SEPARATOR.'[1-9]*.html'));
//var_dump(glob('./sheji/[1-9]*.html'));
//var_dump(glob('./sheji/[^index]*.html'));
 
 
//array_walk(glob(getcwd().'/sheji/[1-9]*.html'),'unlink');
//array_walk(glob('./sheji/[1-9]*.html'),'unlink');
//array_walk(glob(getcwd().DIRECTORY_SEPARATOR.'sheji'.DIRECTORY_SEPARATOR.'[1-9]*.html'),'unlink');
//var_dump(DIRECTORY_SEPARATOR);
//var_dump(unlink('D:shanmaowwwwwwroottiantangtvxyxh4cc/sheji/20312.html'));
?>

相关文章

精彩推荐