Jump to content
Sign in to follow this  

Check If A Folder Is Empty

Recommended Posts


How can I do this?

($folder DO have the trailing \)

FileExists($folder & "*.*")

always returns 1!

Share this post

Link to post
Share on other sites

Try this...It returns 1 if empty, 0 if not, and -1 if directory does not exist.

Func DirIsEmpty($Dir)
    Local $Search, $i, $File

    If StringRight($Dir,1) <> "\" then $Dir = $Dir & "\"
    $Search = FileFindFirstFile($Dir & "*.*")

    If $Search = -1 Then Return -1

    While 1
        $File = FileFindNextFile($Search)
        If @error Then ExitLoop
        $i= $i + 1
        If $i > 2 then ExitLoop
    If $i = 2 then Return 1

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.