澳门新葡萄京官网注册PHP 文件与目录删除程序

function RmDirFiles($indir){ $dh = dir($indir); while($filename =
$dh-read()) { if($filename == . || $filename == ..) continue; else
if(is_file($indir/$filename)) @unlink($indir/$filename); else
$this-RmDirFiles($indir/$filename); } $dh-close();
@rmdir($indir);}//获得某目录合符规则的文件function
GetMatchFiles($indir,$fileexp,$filearr){ $dh = dir($indir);
while($filename = $dh-read()) { $truefile = $indir.’/’.$filename;
if($filename == . || $filename == ..){ continue; } else
if(is_dir($truefile)){
$this-GetMatchFiles($truefile,$fileexp,$filearr); } else
if(preg_match(/.(.$fileexp.)/i,$filename)){ $filearr[] = $truefile; }
} $dh-close();}//删除文件function DeleteFile($filename){$filename =
$this-baseDir.$this-activeDir./$filename;if(is_file($filename)){
@unlink($filename); $t=文件; }else{$t = 目录;if($this-allowDeleteDir==1)
$this-RmDirFiles($filename);}ShowMsg(成功删除一个.$t.!,file_manage_main.php?activepath=.$this-activeDir);return
0;}

function RmDirFiles($indir)
 {
    $dh = dir($indir);
    while($filename = $dh->read()) {
      if($filename == “.” || $filename == “..”)
       continue;
      else if(is_file(“$indir/$filename”))
       @unlink(“$indir/$filename”);
      else
        $this->RmDirFiles(“$indir/$filename”);
    }
    $dh->close();
    @rmdir($indir);
 }
 //获得某目录合符规则的文件
 function GetMatchFiles($indir,$fileexp,&$filearr)
 {
    $dh = dir($indir);
    while($filename = $dh->read())
    {
      $truefile = $indir.’/’.$filename;
      if($filename == “.” || $filename == “..”){
       continue;
      }
      else if(is_dir($truefile)){
       $this->GetMatchFiles($truefile,$fileexp,$filearr);
      }
      else if(preg_match(“/.(“.$fileexp.”)/i”,$filename)){
       $filearr[] = $truefile;
      }
    }
    $dh->close();
 }
 //删除文件
 function DeleteFile($filename)
 {
  $filename = $this->baseDir.$this->activeDir.”/$filename”;
  if(is_file($filename)){ @unlink($filename); $t=”文件”; }
  else{
   $t = “目录”;
   if($this->allowDeleteDir==1) $this->RmDirFiles($filename);
  }
  ShowMsg(“成功删除一个”.$t.”!”,”file_manage_main.php?activepath=”.$this->activeDir);
  return 0;
 }

 //获得某目录合符规则的文件
 

好了,php 删除文件与目录代码是对文件与目录管理时会常用到了,
其实我们是删除文件后再删除目录的,因为php不能直接删除不是null的文件夹哦.

function RmDirFiles($indir)
 {
    $dh = dir($indir);
    while($filename = $dh->read()) {
      if($filename == “.” || $filename == “..”)
       continue;
      else if(is_file(“$indir/$filename”))
       @unlink(“$indir/$filename”);
      else
        $this->RmDirFiles(“$indir/$filename”);
    }
    $dh->close();
    @rmdir($indir);
 }

 代码如下

function GetMatchFiles($indir,$fileexp,&$filearr)
 {
    $dh = dir($indir);
    while($filename = $dh->read())
    {
      $truefile = $indir.’/’.$filename;
      if($filename == “.” || $filename == “..”){
       continue;
      }
      else if(is_dir($truefile)){
       $this->GetMatchFiles($truefile,$fileexp,$filearr);
      }
      else
if(preg_match(“/.(“.$fileexp.”)/i”,$filename)){
       $filearr[] = $truefile;
      }
    }
    $dh->close();
 }

 //删除文件

 代码如下

 function DeleteFile($filename)
 {
  $filename = $this->baseDir.$this->activeDir.”/$filename”;
  if(is_file($filename)){ @unlink($filename); $t=”文件”; }
  else{
   $t = “目录”;
   if($this->allowDeleteDir==1) $this->RmDirFiles($filename);
  }
 
ShowMsg(“成功删除一个”.$t.”!”,”file_manage_main.php?activepath=”.$this->activeDir);
  return 0;
 }

 代码如下

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注