Recursively remove empty parent directories: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
(Recurisvely Remove Empty Parent Folders)
 
No edit summary
Line 1: Line 1:
((PageAuthor|ParallaxTZ))
== Description ==
This function and example function call can be used to recursively delete empty parent folders of a given folder.  
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)
(Courtesy of the folks at www.redbugtech.com)


== The Script ==
<highlight-nsis>
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
</highlight-nsis>
== Usage ==


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


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

Revision as of 15:06, 11 July 2005

((PageAuthor|ParallaxTZ))

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)