php中有没有一个删除非空目录的系统函数?如果没有,请发个目前常用的删除非空目录类。谢谢。

解决方案 »

  1.   


    if ( ! function_exists('delete_files'))
    {
    function delete_files($path, $del_dir = FALSE, $level = 0)
    {
    // Trim the trailing slash
    $path = rtrim($path, DIRECTORY_SEPARATOR);

    if ( ! $current_dir = @opendir($path))
    return;

    while(FALSE !== ($filename = @readdir($current_dir)))
    {
    if ($filename != "." and $filename != "..")
    {
    if (is_dir($path.DIRECTORY_SEPARATOR.$filename))
    {
    // Ignore empty folders
    if (substr($filename, 0, 1) != '.')
    {
    delete_files($path.DIRECTORY_SEPARATOR.$filename, $del_dir, $level + 1);
    }
    }
    else
    {
    unlink($path.DIRECTORY_SEPARATOR.$filename);
    }
    }
    }
    @closedir($current_dir);

    if ($del_dir == TRUE AND $level > 0)
    {
    @rmdir($path);
    }
    }
    }
      

  2.   

    if ( !defined( 'DIRECTORY_SEPARATOR' ) ) {    define( 'DIRECTORY_SEPARATOR',        strtoupper(substr(PHP_OS, 0, 3) == 'WIN') ? '\\' : '/'    ) ;}
      

  3.   

    参考:
    http://www.danhao.org/2010/02/07/php-delete-dir-function/http://www.cnblogs.com/benben7466/archive/2009/11/20/1607147.html
      

  4.   

    php只能删空目录, 
    如果是非空只能遍历删除,这种函数网上一搜一大把
      

  5.   

    system('rm -rf xxx')  请小心使用
      

  6.   

    linux系统可以用:
    用 exec("rm -R $dir"); 
    $dir最好用绝对路径!