Using the Text File Update operation

ImportantThe following article uses options that are available starting with the Enterprise edition and project type.

There are cases when files installed by the package or files that are already on the disk need to be updated, either based on some machine specifications, as a result of some actions or based on the user input or selection.

Updating a text file installed by the package has never been easier using the text file update which supports 2 different operations:

  • Create or append: If the file does not exist, a new file with the name specified in the Text File Properties dialog will be created containing the text written. If the specified file already exists the content from this field will be appended at the end of the specified text file.
  • Replace: This will allow to search for specific text and update it.

The Text File Update operation can be used to update any file type like: .TXT, .BAT, .RTF, .DOC, not just .TXT files.

1. Create project

After launching Advanced Installer, you will be presented with a dialog where you can choose the type of the project you want to create.

Start Page

Select Enterprise and press the Create Project button. The new project has been created and from now on you will edit it.

SaveSave the project and give it an appropriate name - let's say "Text File Update Sample" for this example.

2. Enter product details

Now you can see the main view split into two panes. In the left pane, you can see all the options you have to edit in your current project, grouped in categories.

Product DetailsSwitch to “Product Details” page to set the information seen by the user for your installation package. Fill the fields in the right pane with the corresponding data.

Product Details

The information from this view will be displayed in the Control Panel.

3. Add files to your project

The next step is to add to the project the files and/or folders that compose your application.

Files and FoldersSelect “Files and Folders” from the “Resources” menu on the left pane.

Add filesClick on the [ Add Files ] toolbar button and select the files of your application, or use the drag-and-drop to add resources from the disk to the project.

This is how the file that is about to be updated looks like on disk:

File overview

The file seems to be a combination of an .xml structure and .json. We will use the text file update operation to update all those placeholders, but also to append at the end of the file when the file was updated, with current date & time of the installation.

4. Define the Text File Update operation

Files, Folders, and Shortcuts

To create the text file update operation, use the toolbar option or the context menu to quickly add the text file update operation:

Text file toolbar

The file update operation needs to match the file name that is getting updated.

Let's configure the text file update operation:

Text file config

There are several Find & Replace operations added for each placeholder. Also, the text file update operation matches the file name from disk added as an application resource.

NoteBy default, the option to create a backup of the file before updating is enabled. If you prefer not to create a backup before the update operation, you can simply disable the "Create backup before upgrade" option.

Here is how the overview of the Append/Create & Replace operations looks like:

Operations overview

All the properties used by the text file update are MSI properties that are set during installation. You can use custom properties that are set as a result of a search operaion, custom action or user input.

NoteThe Text File Update can contain multiple replace operations but a single append/create operation can be declared per "Text File Update". Also, the unnecessary operations can be removed and only a single one be kept.

5. Build and install

Upon building and installing the resulting setup package, you will observe that the text file has been updated as specified. Here is how the file looks on disk after installation:

File updated

6. Video tutorial

A video demonstrating the dynamic updating of text in a file, whether it's an existing file on the machine or a newly installed file. Using standard search and replace methods, you can create a new file from scratch or append content to existing files.