Delete dir only if empty: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
m (Updated author links.) |
m (Newline) |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
{{PageAuthor|camillo}} | |||
<div style="border: 1px solid #808040; background-color:#f8f880; color:#000; padding:0.3em;"><b>Warning: </b>RMDir without the /r switch will only delete empty directories, no extra code is required.</div> | |||
< | |||
== 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. | ||
''' You can now delete empty directories by simply using RMDir without the /r switch. | |||
== How To Use == | == How To Use == | ||
Line 34: | Line 37: | ||
Comments to 'camillo@rockit.it' | Comments to 'camillo@rockit.it' | ||
[[Category:Deprecated]] |
Latest revision as of 00:58, 19 June 2023
Author: camillo (talk, contrib) |
Warning: RMDir without the /r switch will only delete empty directories, no extra code is required.
Description
Here is a simple but useful function to delete a directory ONLY if it is empty.
You can now delete empty directories by simply using RMDir without the /r switch.
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'