长枪不倒 发表于 2015-8-28 09:08:43

PHP写的CVS文件夹清理工具

前些日子有朋友用C#写的这种工具~~我是用TortoiseCVS, 如果不连接服务器无法生成发布文件~~今天CVS服务器没启动,无法继续随即用PHP写一个耍耍~~没什么复杂,递归删除文件夹~~呵呵~



<?
/**//**
* CVS_Clean.php - Clean CVS folder from the target path.
*
* Copyright (c) 2002-2005 mikespook & swill
*
*/
require_once('File/Find.php');

class CVS_Clean
{
var $br;
var $slash;
var $path;
var $r;

function CVS_Clean()
{
    if (strtoupper(substr(PHP_OS, 0,3) == 'WIN'))
    {
      $this->slash = "\\";
    }
    else
    {
      $this->slash = "/";
    }
    if (isset($_SERVER['argc']))
    {
      $this->br = "\n";
    }
    else
    {
      $this->br = "<br/>";
    }
    if (isset($_GET['path']))
    {
      $this->path = $_GET['path'];      
    }
    elseif (isset($_SERVER['argv']))
    {
      $this->path = $_SERVER['argv'];      
    }
    if (isset($_GET['r']))
    {
      $r = $_GET['r'];
    }
    elseif (isset($_SERVER['argv']))
    {
      $r = $_SERVER['argv'];
    }
    $this->r = strtolower($r) !== '-nr';
}

function help()
{
    echo "I will show you this message that you didn`t input the paramater <dir> or the paramater <dir> is not a valid directory.".$this->br.$this->br;
    echo "mikespook <mikespook@gmail.com>".$this->br;
    echo "http://www.xxiyy.com".$this->br.$this->br;
    echo "Useage: CVS_Clean <dir> ".$this->br;
    echo "Clean CVS folder from the directory".$this->br.$this->br;
    echo "<dir>\tThe directory you want to clean without slash (".$this->slash.") at the end.".$this->br;
    echo "-nr\tDon`t remove the CVS folder recursively.";
}

function run()
{
    if (!is_dir($this->path))
    {
      $this->help();
    }
    else
    {
      $this->clean($this->path);
    }
}

function clean($path)
{
    $finder = File_Find::mapTreemultiple($path, 2);   
    foreach($finder as $name => $item)
    {
      if (is_array($item))
      {
      if ($this->r)
      {
          $this->clean($path.$this->slash.$name);
      }
      if ($name === 'CVS')
      {         
          $this->rm($path.$this->slash.$name);         
      }
      }
   }
}

function rm($path)
{
    $finder = File_Find::mapTreemultiple($path, 1);
    foreach($finder as $item)
    {
      unlink($path.$this->slash.$item);
    }
    rmdir($path);
}
}

$main = new CVS_Clean();
$main->run();
?>
页: [1]
查看完整版本: PHP写的CVS文件夹清理工具