Delete dir only if empty: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Added category links.)
m (Adding new author and category links.)
Line 1: Line 1:
{|align=right
{{PageAuthor|camillo}}
|<small>Author: [[{{ns:2}}:camillo|camillo]] ([[{{ns:3}}:camillo|talk]], [[{{ns:-1}}:Contributions/camillo|contrib]])</small>
 
|}
<br style="clear:both;">
== Description ==
== Description ==
Here is a simple but useful function to delete a directory ONLY if it is empty.
Here is a simple but useful function to delete a directory ONLY if it is empty.
Line 35: Line 33:
Comments to 'camillo@rockit.it'
Comments to 'camillo@rockit.it'


[[{{ns:14}}:Disk, Path & File Functions]]
[[Category:Disk, Path & File Functions]]

Revision as of 12:04, 24 June 2005

Author: camillo (talk, contrib)


Description

Here is a simple but useful function to delete a directory ONLY if it is empty.

How To Use

Put directory in $0 and call the function.

Example

StrCpy $0 "$SMPROGRAMS\PwStore"
Call un.DeleteDirIfEmpty

The Function

Function un.DeleteDirIfEmpty
  FindFirst $R0 $R1 "$0\*.*"
  strcmp $R1 "." 0 NoDelete
   FindNext $R0 $R1
   strcmp $R1 ".." 0 NoDelete
    ClearErrors
    FindNext $R0 $R1
    IfErrors 0 NoDelete
     FindClose $R0
     Sleep 1000
     RMDir "$0"
  NoDelete:
   FindClose $R0
FunctionEnd

Comments to 'camillo@rockit.it'