Jump to content

Check If A Folder Is Empty


Recommended Posts

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...