Our current update included the deletion of over 1400 files (mostly unused textures that we purged from source control). I decided that manually entering delete file or delete folder blocks for all of them is too much work and came up with a workaround.
I get a list of files from a directory diff, saving the list to a text file "delete.txt". Each file is listed as e.g. ".\data\textures\faketexture.bmp". The diff tool lists files with the diff root as '.' automatically. On subsequent updates I will append the new list at the end of this file, so users upgrading from v.1 to v.3 don't miss the files deleted in v.2.
I created a batch file containing:
This batch file iterates through the files listed in delete.txt, deleting each and attempting to remove the subdirectory if the deletion emptied it.@echo off
for /f "delims=" %%i in (delete.txt) do (del "%%~fi" 2>nulrd "%%~dpi" 2>nul)
"delims=" replaces the default delimiter set (space and tab) with an empty set. This ensures that each line is treated as a single whole entry. Without this, the batch can't delete a file containing a space.
"%%~fi" expands each entry to a fully qualified path, enclosed in quotes. "%%~dpi" expands each entry to a drive letter and path with no file name, enclosed in quotes. The quotes are important in case the user has installed to a path with spaces in, which is likely.
2>nul throws away all error output, so the user doesn't see "Could not find foo" for files that don't exist or "The directory is not empty" if the file was not the last in the directory.
In my SetupBuilder script, I added
The Run Program entry has 'Hide Window' checked, and 'Default Directory' set to "%_SB_INSTALLDIR%". The default directory ensures that when delete.bat runs, its current directory corresponds to the root of the files in delete.txtInstall File "C:\Installer\delete.bat" to %_SB_INSTALLDIR%\delete.bat
Install File "C:\Installer\delete.txt" to %_SB_INSTALLDIR%\delete.txt
Run Program %_SB_INSTALLDIR%\delete.bat (Always Install) (Wait)
Delete Local Files "%_SB_INSTALLDIR%\delete.bat"
Delete Local Files "%_SB_INSTALLDIR%\delete.txt"
I placed these lines in the [ Install Files ] section, before the Install File *.* line. In this way, if a file gets deleted and later re-added, it will end up being downloaded again, but is ensured to end up in the final installation.