- NSIS Discussion
- Delete empty dirs/subdirs from directory file - strange behaviour
Archive: Delete empty dirs/subdirs from directory file - strange behaviour
saschagottfried
21st September 2006 16:27 UTC
Delete empty dirs/subdirs from directory file - strange behaviour
I report a strange behaviour for the combination of instructions: Locate, RMDir
I use filelists to install and for uninstallation. Installation works well, but I have to remove empty dirs after deleting every file read from the filelist.
I tried Recfind, Locate with Callbackfunction, read a lot in the forum. After generating the DirList with Locate or RecFind, I process it from the end to start to delete empty dirs/subdirs. But RMDir can not delete anything.
*Manual deletion of those directories works.
*I know that current directory can't be deleted - I switch before deletion.
*I test whether the directory are recognized as dirs and if they are empty or not.
* I already tried /REBOOTOK, that deleted the subdirs after Reboot. This would just be a lazy fix. I KNOW that no Reboot is necessary.
Strange Behaviour:
I splitted the code into two sections. One creates the directorylist. The other one reads it and invokes RMDir on those paths.
If I execute both section afterwards, RMDir can not delete dirs. Thus I used "/o" on second section to skip it in first run of "installer". The list got created. Installer exits without trying to read and delete the dirs. Second Run: I edited my source code to unselect the first section. After execution the dirlist got read and deleted without any problems. "Strange, huh" as Guybrush Threepwood would comment in this case.
I would like to have first some explanation of this behaviour and in second place suggestions for existing "solutions" for this task.
I added the code as attachment. You have to create "C:\testdir" with some subdirs hierarchy in it.
kichik
22nd September 2006 12:34 UTC
The problem is with GetSize. It doesn't properly close the search handles it opens. Locate seems a little problematic on the subject as well. When its callback passes stop it and in another case I still haven't figured out, it doesn't close the last opened handle.
If Locate or RecFind is giving you problems, you can use my old function. As for GetSize, either wait for Instructor to fix it, or implement your own solution using Locate.
saschagottfried
22nd September 2006 14:01 UTC
I am really happy that you cared about my problem. Great work.
I started to use GetSize to prove that Locate writes the same number of dirs in my dirlist-file as GetSize reports. I kept GetSize in my code and thus switching from Locate to RecFind did not helped. Now I know the reason. Well done. I really appreciate your work for all forum members.
DrDan
8th June 2007 14:05 UTC
Still seems to happen...
I simply can't get the example "Example (Delete empty directories):" in "Appendix E.1.2 Locate" to work.
Any idea if this has been or will be fixed?
saschagottfried
13th June 2007 17:08 UTC
Please provide more information! What is your problem, what code you used to solve this and so on. Please append your code and describe its purpose.
DrDan
14th June 2007 09:31 UTC
One of my colleagues helped me to work out another algorithm to do this without using Locate.
The problems I was experiencing with the Locate example were directories not being deleted.
saschagottfried
14th June 2007 15:00 UTC
Fine. But the idea of a installation tool could be that you just use built in function without the need to develop a special workaround for simple task.
If you do not mind, share your example with us. Imagine the next example you can not get to run. Develop the next algorithm or ask the community? Anyways, I think if there is a problem with Locate you should tell us. Cheers!
DrDan
15th June 2007 10:12 UTC
All my fault!!!!
Luckily, I have finally had some time to look into this carefully, and I am completely wrong. :D :D :D The example does work correctly. :D :D :D :D :D :D :D
I withdraw my previous comment that the example did not work.
Apologies for the confusion.
DrDan
15th June 2007 10:17 UTC
Attached example
And here's an example that works.
If you wish to run it, change the
!define MY_FILE
on line 18 to any dummy file you have lying around.
DrDan
15th June 2007 10:18 UTC
Oops
Missed the attachment.
Instructor
15th June 2007 10:37 UTC
${locate::RMDirEmpty} fast algorithm
saschagottfried
15th June 2007 12:10 UTC
@Instructor:
Is your Plugin the code base for FileFunc.nsh? What about your special RMDirEmpty function. Will it find its way into main NSIS? Anyways, I will check this function next time.
@DrDan:
Thanks a lot. Its always like this: as soon as you do it right, it works. Great stuff! *g*