Recursively remove empty parent directories: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
No edit summary
No edit summary
Line 1: Line 1:
((PageAuthor|ParallaxTZ))
{{PageAuthor|ParallaxTZ}}


== Description ==
== Description ==

Revision as of 15:07, 11 July 2005

Author: ParallaxTZ (talk, contrib)


Description

This function and example function call can be used to recursively delete empty parent folders of a given folder.

(Courtesy of the folks at www.redbugtech.com)

The Script

Function un.RMDirUP
         !define RMDirUP '!insertmacro RMDirUPCall'
 
         !macro RMDirUPCall _PATH
                push '${_PATH}'
                Call un.RMDirUP
         !macroend
 
         ; $0 - current folder
         ClearErrors
 
         Exch $0
         ;DetailPrint "ASDF - $0\.."
         RMDir "$0\.."
 
         IfErrors Skip
         ${RMDirUP} "$0\.."
         Skip:
 
         Pop $0
FunctionEnd

Usage

RMDir /r "$INSTDIR"     ;remove $INSTDIR and all files/subfolders
${RMDirUP} "$INSTDIR"   ;remove $INSTDIR's parents (if each is empty ONLY)