- NSIS Discussion
- Easy way to remove a folder and its files and subfolders using wildcards
Archive: Easy way to remove a folder and its files and subfolders using wildcards
bambou51
19th September 2006 14:50 UTC
Easy way to remove a folder and its files and subfolders using wildcards
Is there an easy way to remove a folder and its files and subfolders using wildcards like this:
RMDir /r "c:\folder*"
I know that it can't work with RMDir but I was not able to find any simple solution (otherwise I will have to get the list of all the matching folders and remove them one by one)
Afrow UK
19th September 2006 17:33 UTC
Doesn't this work?
RMDir /r "c:\folder"
-Stu
bambou51
20th September 2006 07:27 UTC
No it is not working, because I have a bunch of folders called
folder1, folder6, folderXXX, and I want to remove all of them without having the complete list, that's why I need to use wildcards.
CancerFace
20th September 2006 07:52 UTC
How about this:
Use FindFirst/FindNext to get everything in your folder (files and subfolders), then check with DirState that what you have is not a file (the function returns -1 in case you have a file), match some pattern with WordFind (from your post it sounds that all the folders are named FolderXXX, so look for 'Folder') then use RMDir to remove only those folders that match your criteria
Hope this helps
CF
Afrow UK
20th September 2006 12:23 UTC
You don't need to use DirState. Just check that it's a folder by doing:
IfFileExists $R0\*.* folder notfolder
-Stu
bambou51
20th September 2006 13:03 UTC
ok Thanks
One strange thing is that sometimes when I call
RMDir /r my_folder
the content of the folder is deleted (even subfolders), but the folder itself still exists.
It 's not a right problem because I am able to delete the folder from Windows explorer.
But most of the time it is working fine.
Animaether
21st September 2006 03:12 UTC
were you 'in' the folder with Explorer or anything else at the time? If so, that's why it wouldn't be deleted. Typically this is when an application sets that folder as its' 'working folder', but there can be many causes.
bambou51
21st September 2006 09:55 UTC
None of these folders were displayed (or opened) during my RMDir call.
I even try to kill my explorer before the call but it doesn't change anything.
Afrow UK
21st September 2006 10:56 UTC
How about SetOutPath?
-Stu
Animaether
21st September 2006 12:54 UTC
And if you're still stuck, check out:
http://ccollomb.free.fr/unlocker/
It should list whatever processes are touching that folder and preventing you from deleting it.