How can I check if the directory is empty?
How can I check if the directory is empty?
Sugestion (for the creators):
- Can you add an function IfDirectoryIsEmpty?
- Can you add an option in RMDir command "/ifempty" like the
"DeleteRegKey /ifempty"?
Archive: How can I check if the directory is empty?
How can I check if the directory is empty?
How can I check if the directory is empty?
Sugestion (for the creators):
- Can you add an function IfDirectoryIsEmpty?
- Can you add an option in RMDir command "/ifempty" like the
"DeleteRegKey /ifempty"?
Emtpy dir over FindFirst
Hi!:)
It's not difficult and also not easy :
A directory may exist and is empty. Then the files "." and ".." will exist. If there are more files at least a third file must exist.
I hope Justin will implement a command to to that!;)
Example with Function "IsDirEmtpy"
Strcpy $0 "c:\temp\test"
call IfDirEmpty
ifErrors 0 x1
;Dir may be empty or does not exist!
MessageBox MB_OK "Dir $0=empty or not existent"
goto x2
x1:
MessageBox MB_OK "Dir $0=not empty"
x2:
;Dir = $0
;Error Flag 1=empty or not existent
Function IsDirEmpty
push $R1
push $R2
ClearErrors
IfFileExists "$0" 0 not_exists
FindFirst $R1 $R2 "$0\*.*"
IfErrors no_files
FindNext $R1 $R2
IfErrors no_files
FindNext $R1 $R2
IfErrors no_files
;nicht leer
FindClose $R1
ClearErrors
goto end
;Leer
no_files:
FindClose $R1
SetErrors
goto end
;nicht existent
not_exists:
SetErrors
end:
pop $R2
pop $R1
FunctionEnd
Actually it's not nearly that complicated
I tend to use the following, works for me.
ClearErrors
RMDir "$DIR"
IfErrors DirNotEmpty
It won't delete the directory if it's not empty.
Maragato,
remember me? I already answered this question which you sent me by e-mail!!!
Check your inbox!
-Hn3.
I found by my self the solution for this question!
Function RemoveEmptyDir
IfFileExists "$0\*.*" IsItEmpty EndExistDir:
IsItEmpty:
FindFirst $R1 $R2 "$0\*.*"
FindNext $R1 $R2
FindNext $R1 $R2
FindClose $R1
StrCmp "$R2" "" DirEmpty EndExistDir
DirEmpty:
RMDir "$0"
EndExistDir:
FunctionEnd
StrCpy $0 "$TEMP"
Call RemoveEmptyDir
Thanks folks!
You found it yourself,
well done. So you neglected our post to be able to struggle yourself to a solution that has already been posted and sent to you by e-mail and which is more efficient (to my opinion). Pay attention and take a look at the effort we're doing for you.
Next time, if you choose to neglect our input, just do not post your question, will you...
-Hn3.