删除4万多个文件 1秒左右
直接上代码:
[code lang=”php”]
<?php
$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."<Br>";
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:\shanmao\www\wwwroot\tiantangtv\xyxh4cc/sheji/20312.html’));
?>
[/code]
其中 :glob 查找文件 。可用正则
完整版:可删除单栏目和多栏目。需要验证chckcode。删除前展示待删除项总数,然后确认删除。
[code lang=”php”]
<?php
if($_GET[‘checkcode’]!="xxxxxxxxxxx"){
echo ‘error url.’;
exit;
}
if(!$_GET[‘lanmu’]){
exit("no this channel.");
}
if($_GET[‘lanmu’]=="all"){
$lanmu = array("action","tiyu","yizhi","sheji","gaoxiao","maoxian","qipai","celue","minjie","xiuxian","zhuangban","ertong","jingying","webgame");
foreach($lanmu as $key=>$v2){
$mstdel[$key] =glob(getcwd().DIRECTORY_SEPARATOR.$v2.DIRECTORY_SEPARATOR.'[1-9]*.html’);
$zongdel += count($mstdel[$key]);
}
}else{
$mstdel[] =glob(getcwd().DIRECTORY_SEPARATOR.$_GET[‘lanmu’].DIRECTORY_SEPARATOR.'[1-9]*.html’);
$zongdel =count($mstdel[0]);
}
if($_GET[‘do’]=="del"){
$i=0;
foreach($mstdel as $val){
foreach($val as $val2){
if(unlink($val2)) $i++;
}
}
echo ‘del success: ‘.$i;
}else{
echo "seach html:".$zongdel;
$delurl = "/delall.php?lanmu=".$_GET[‘lanmu’]."&checkcode=".$_GET[‘checkcode’]."&do=del";
echo ‘<br><a href="’.$delurl.’">click here to confirm delete</a>’;
}
?>
[/code]
“php批量删除特定栏目下的特定html文件”的2个回复
评论已关闭。