Delete dir only if empty: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Wikipedia python library)
 
m (Updated author and download links, and changed format of some pages.)
Line 31: Line 31:
Comments to 'camillo@rockit.it'
Comments to 'camillo@rockit.it'


 
Page author: [[User:camillo|camillo]]
Page author: camillo

Revision as of 12:35, 23 April 2005

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'

Page author: camillo