djdungcuty

djdungcuty

Active Member

Dưới đây là code PHP với chức năng loại bỏ toàn bộ thư mục không chứa tập tin nào bên trong.
Và đây là code:
PHP:
function RemoveEmptySubFolders($starting_from_path) {
    // Trả về true nếu thư mục này không chứa tập tin
    function IsEmptyFolder($folder) {
        return (count(array_diff(glob($folder.DIRECTORY_SEPARATOR."*"), Array(".", ".."))) == 0);
    }
    // trả về true nếu ít nhất một thư mục trống đã được gỡ bỏ
    function DoRemoveEmptyFolders($from_path) {
        if(IsEmptyFolder($from_path)) {
            rmdir($from_path);
            return true;
        } else {
		// Code được viết bởi Vn4ever.Com
            $Dirs = glob($from_path.DIRECTORY_SEPARATOR."*", GLOB_ONLYDIR);
            $ret = false;
            foreach($Dirs as $path) {
                $res = DoRemoveEmptyFolders($path);
                $ret = $ret ? $ret : $res;
            }
            return $ret;
        }
    }
    while (DoRemoveEmptyFolders($starting_from_path)) {}
}

Copy hãy ghi nguồn Vn4ever.Com nhé ;)
 

Facebook Comments

Similar threads

Admin
Replies
0
Views
5K
AdminAdmin is verified member.
Admin
Admin
Replies
0
Views
3K
AdminAdmin is verified member.
Admin
Admin
Replies
1
Views
1K
mcent
M
Admin
Replies
0
Views
991
AdminAdmin is verified member.
Admin
N
Replies
1
Views
923
AdminAdmin is verified member.
Admin
Admin
Replies
0
Views
2K
AdminAdmin is verified member.
Admin
congtust24
Replies
5
Views
1K
AdminAdmin is verified member.
Admin
blog4me
Replies
0
Views
743
blog4meblog4me is verified member.
blog4me