<?php

function delgit($dir)
{
    $dh = opendir($dir);
    //找出所有".git" 的文件夹：
    while ($file = readdir($dh)) {
        if ($file != "." && $file != "..") {
            $fullpath = $dir . "/" . $file;
            if (is_dir($fullpath)) {
                if ($file == ".git") {
                    delgitdir($fullpath);
                } else {
                    delgit($fullpath);
                }
            }
        }
    }
    closedir($dh);
}

function delgitdir($gitdir)
{
    //先删除目录下的文件：
    $dh = opendir($gitdir);
    while ($file = readdir($dh)) {
        if ($file != "." && $file != "..") {
            $fullpath = $gitdir . "/" . $file;
            if (is_dir($fullpath)) {
                delgitdir($fullpath);
            } else {
                unlink($fullpath);
            }
        }
    }
    closedir($dh);
    //删除目录文件夹
    if (rmdir($gitdir)) {
        return true;
    } else {
        return false;
    }
}

$dir = __DIR__. '/vendor/api';
delgit($dir);
