Jump to content

Recommended Posts

Posted

How do I check if a folder is empty?

$fldr1 = "F:\MediaSync\test\"

If FileExists( $fldr1 & "*.*") Then
    MsgBox(0,"i","Not empty")
Else
    MsgBox(0,"i","Empty")
EndIf
This doesn't work.

iPod + Online calendars = iPodCALsync

  • Developers
Posted

How do I check if a folder is empty?

$fldr1 = "F:\MediaSync\test\"

If FileExists( $fldr1 & "*.*") Then
    MsgBox(0,"i","Not empty")
Else
    MsgBox(0,"i","Empty")
EndIf
This doesn't work.
FileFindFirstFile() can do that for you and then test for @error :

Return Value

Success: Returns a search "handle" for use with subsequent FileFindNextFile functions.

Failure: Returns -1 if error occurs. If the Folder is empty the @error is set to 1.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

FileFindFirstFile() can do that for you and then test for @error :

Return Value

Success: Returns a search "handle" for use with subsequent FileFindNextFile functions.

Failure: Returns -1 if error occurs. If the Folder is empty the @error is set to 1.

Like this?
$fldr1 = "F:\MediaSync\emptyfolder\"
$sizefldr1 = DirGetSize($fldr1)

If $sizefldr1 = "0" Then
    MsgBox(0,"i","Not empty, " & $sizefldr1)
Else
    MsgBox(0,"i","Empty")
EndIf

iPod + Online calendars = iPodCALsync

Posted

You could one or more 0Kb files in the directory.....

:P

If you use the extended mode then the array returned from this function is a single dimension array containing the following elements:

$array[0] = Size

$array[1] = Files count

$array[2] = Dirs Count

It could be preference to what is best for the task. No doubt, JdeB, that your reply is just as useful. :nuke:

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
×
×
  • Create New...