Sign in to follow this  
Followers 0
ezzetabi

Check If A Folder Is Empty

2 posts in this topic

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
    WEnd
    FileClose($Search)
    If $i = 2 then Return 1
EndFunc

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  
Followers 0