Pieter Posted August 20, 2006 Share Posted August 20, 2006 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") EndIfThis doesn't work. iPod + Online calendars = iPodCALsync Link to comment Share on other sites More sharing options...
Developers Jos Posted August 20, 2006 Developers Share Posted August 20, 2006 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") EndIfThis 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. Link to comment Share on other sites More sharing options...
MHz Posted August 20, 2006 Share Posted August 20, 2006 Hi Pieter, Look at DirGetSize() in the helpfile. I'm sure it may suit your need. Link to comment Share on other sites More sharing options...
Developers Jos Posted August 20, 2006 Developers Share Posted August 20, 2006 Hi Pieter,Look at DirGetSize() in the helpfile. I'm sure it may suit your need.You could one or more 0Kb files in the directory..... 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. Link to comment Share on other sites More sharing options...
Pieter Posted August 20, 2006 Author Share Posted August 20, 2006 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 Link to comment Share on other sites More sharing options...
MHz Posted August 20, 2006 Share Posted August 20, 2006 You could one or more 0Kb files in the directory..... 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 CountIt could be preference to what is best for the task. No doubt, JdeB, that your reply is just as useful. Link to comment Share on other sites More sharing options...
MHz Posted August 20, 2006 Share Posted August 20, 2006 (edited) Like this?More like this $fldr1 = "F:\MediaSync\emptyfolder\" $sizefldr1 = DirGetSize($fldr1, 1) If Not @error Then If Not $sizefldr1[1] And Not $sizefldr1[2] Then MsgBox(0,"i","Empty") Else MsgBox(0, "i", "Not empty: " & $fldr1) EndIf Else MsgBox(0, "i", "Does not exist: " & $fldr1) EndIf Edit: Changed variable in MsgBoxes Edited August 20, 2006 by MHz Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now