- NSIS Discussion
- deleting question
Archive: deleting question
gieltje
2nd April 2004 07:04 UTC
deleting question
Hi all,
I need to delete some folders that are not in the install folder, and have varying names.
I cannot simply delete the folder in which they are because it is a system folder.
example;
c:\blaat
c:\blaat\1
C:\blaat\2
Now 1 & 2 need to be deleted, but blaat cannot be.
How do I this?
evilO
2nd April 2004 07:37 UTC
Hi :)
4.9.1.8 RMDir
[/r|/REBOOTOK] directory_name
Remove the specified directory (which should be a full path). Without /r, the directory will only be removed if it is completely empty. If /r is specified, the directory will be removed recursively, so all directories and files in the specified directory will be removed. If /REBOOTOK is specified, and the directory cannot be overwritten, then the directory will be deleted when the system reboots -- if the directory will be removed on a reboot, the reboot flag will be set. The error flag is set if the directory cannot be removed.
I don't know exactly if I understood your problem, but to remove these directories you just have to do that:
- If the folders are empty:
RmDir c:\blaat\1
RmDir c:\blaat\2
- If the folders are *not* empty:
RmDir /r c:\blaat\1
RmDir /r c:\blaat\2
Is that what you want to achieve ?
evilO/Olive
gieltje
2nd April 2004 07:39 UTC
allmost, another problem is the names of these dirs are always changing so RMDir "c:\blaat\*" should be it but it does not delete every dir in c:\blaat but trys to remove c:\blaat which cannot be done (because it is a system folder)
evilO
2nd April 2004 13:36 UTC
Ok, I got it now. You can use the following code to achieve this, but BE CAREFUL: it will remove EVERY SUBDIRECTORY (not the files) of the specified directory. Especially if "c:\blaat" is a system folder.
EmptyFolder
Exch $R0; Name of the folder to empty
Push $R1 ; Search handle
Push $R2; Current file or folder
${If} ${FileExists} "$R0\\*.*" ; If the current element is a directory
ClearErrors
FindFirst $R1 $R2"$R0\\*.*" ; Starts the search
${Unless} ${Errors}
${Do}
${
Select} $R2
${Case2} "." ".." ; If the current element is '.' or '..' do nothing
${CaseElse} ; Otherwise
${If} ${FileExists} "$R0\\$R2\\*.*" ; If the current element is a directory
Rmdir/r "$R0\\$R2" ; Removes it
${EndIf}
${EndSelect}
FindNext $R1 $R2 ; Continues the search
${LoopUntil} ${Errors}
FindClose $R1 ; Closes the search handle
${EndUnless}
${EndIf}
Pop $R2
Pop $R1
Pop $R0
FunctionEnd
>
And to use it:
Push "c:\\blaat"
>Call EmptyFolder
>
I hope that helps :)
evilO/Olive
gieltje
2nd April 2004 17:16 UTC
it does the correct thing, but wont compile:confused:
${If} ${FileExists} "$R0\*.*" ; If the current element
that's the line it breaks on:hang:
Joost Verburg
2nd April 2004 22:17 UTC
You should include LogicLib.nsh
gieltje
3rd April 2004 17:02 UTC
Variable "_LOGICLIB_TEMP" not referenced, wasting memory!
how do I define it?
Joost Verburg
3rd April 2004 17:45 UTC
You don't have to define anything, it can safely be ignored.
gieltje
3rd April 2004 19:05 UTC
damn I hate ignoring errors
Joost Verburg
3rd April 2004 20:09 UTC
It's not an error. A variable has been declared but is not used.
gieltje
4th April 2004 12:09 UTC
if I dont include LogicLib.nsh it wont compile so I guess it is being used
Joost Verburg
4th April 2004 12:45 UTC
It's a variable that is not used by the part of LogicLib you are using.
gieltje
22nd September 2004 08:44 UTC
${If} ${FileExists} "$R0\*.*" ; If the current element is a directory
ClearErrors
FindFirst $R1 $R2 "$R0\*.*" ; Starts the search
${Unless} ${Errors}
${Do}
${Select} $R2
${Case2} "." ".." ; If the current element is '.' or '..' do nothing
${CaseElse} ; Otherwise
${If} ${FileExists} "$R0\$R2\*.*" ; If the current element is a directory
Rmdir /r "$R0\$R2" ; Removes it
${EndIf}
Delete "$R0\*.*" ; Removes every file from the root folder
${EndSelect}
FindNext $R1 $R2 ; Continues the search
${LoopUntil} ${Errors}
FindClose $R1 ; Closes the search handle
${EndUnless}
${EndIf}
Added a little thing to remove every file in the root folder if anyone is interested