Archive: Remove all files and directories except one


Remove all files and directories except one
In our installer, we install several files and several subdirectories with files in them. I have been asked to make the uninstaller remove all directories and files except one specific subdirectory (let's call it dirA). When a user then re-installs (either by uninstalling then installing OR by installing over), the desired behavior is, check the files in dirA and if a file that is being extracted from the installer already exists, it should not overwrite it. If a file does not exist, it should be extracted into that directory.

I have seen solutions elsewhere in this forum for recursively removing all files and for writing a file only if it doesn't already exist. However, I haven't seen one that does both. Anyone have a good way of doing this?

I should also mention that the files that are in the installer could change regularly between builds. In other words, I need a method that does not hardcode the file names in the installer source file.

TIA for any ideas.


1. To uninstall all files except one subdir: use FindFirst, FindNext and FindClose (NSIS User Manual 4.9.5.9) for top dir and remove all files and folders except dirA (StrCmp). You can use both RMDir and Delete to every found name.
2. SetOverwrite mode (Manual 4.8.2.8), example included.
3. Use folder names or file name templates with * to install "not hardcoded file names" (see manual for File command).


http://nsis.sourceforge.net/wiki/Del...one_dir_/_file

-Stu


To Afrow UK: BTW 'find' function works fine with * instead of *.* :)