Old 25th March 2002, 18:46   #1
maragato
Junior Member
 
Join Date: Mar 2002
Location: Rio Grande do Sul
Posts: 15
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"?
maragato is offline   Reply With Quote
Old 25th March 2002, 20:12   #2
superrock
Member
 
superrock's Avatar
 
Join Date: Jan 2002
Location: Graz, Austria
Posts: 50
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
superrock is offline   Reply With Quote
Old 25th March 2002, 23:55   #3
Pomflain
Member
 
Pomflain's Avatar
 
Join Date: Aug 2001
Posts: 83
Smile 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.
Pomflain is offline   Reply With Quote
Old 26th March 2002, 08:03   #4
Smile2Me
Guest
 
Posts: n/a
Maragato,

remember me? I already answered this question which you sent me by e-mail!!!
Check your inbox!

-Hn3.
  Reply With Quote
Old 27th March 2002, 20:49   #5
maragato
Junior Member
 
Join Date: Mar 2002
Location: Rio Grande do Sul
Posts: 15
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!
maragato is offline   Reply With Quote
Old 27th March 2002, 21:36   #6
Smile2Me
Guest
 
Posts: n/a
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.
  Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump