wangzhibo
2023-10-31 86070cd00485c47a2c5c3ffa4a9bae6648dd05c6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
; RMDirIfNotJunction 1.1 (2020-04-29)
;
; Removes an empty directory if it is not a junction
;
; Usage: ${RMDirIfNotJunction} REMOVE_PATH
 
!include "FileFunc.nsh"
 
Function RMDirIfNotJunction
    ;Start with a clean slate
    ClearErrors
    
    ;Get our parameters
    Exch $0 ;REMOVE_PATH
    Push $1 ;TempVar
    
    ;Determine if it is a junction
    ${GetFileAttributes} "$0" "REPARSE_POINT" $1
    
    ${If} $1 == 0
        ;Not a junction, remove the directory if empty
        RMDir $0
    ${EndIf}
    
    ;Clear the stack
    Pop $1
    Pop $0
FunctionEnd
 
!macro RMDirIfNotJunction REMOVE_PATH
  Push `${REMOVE_PATH}`
  Call RMDirIfNotJunction
!macroend
 
!define RMDirIfNotJunction '!insertmacro "RMDirIfNotJunction"'