Add Lines To Files

There are two methods to add text to the start or end of a file.

1. Binary Mode Prepend and Append Function

The Prepend / Append function is a special operation that is available in the Binary Mode dialog for the Search string. This function allows you to add the Replace string to the top or bottom of the files specified by the mask & path.

To activate prepend or append, click on the Search & Replace b path4 Add Lines to Files button next to the Search string in the main window or the Script Editor and select “Add at top of file” or “Add at bottom of file”. The Replace string will be inserted accordingly when you do a Search/Replace. A confirmation dialog allows you to confirm whether or not to perform prepend and append replacements (see when replacement prompts are set to “Prompt on All” (see Replace Options).

See Special Script Prepend-Append Operators for information on operators that are available for scripted operations.

2. Regular Expressions

You can use a regular expression operator to identify a string at the very top or bottom of a file and combine this with a replace term that includes the appropriate line end character for the type of file you are operating on.

For example, the add a string to the top of a file, perhaps use:

 Search: ^*
 Replace: What you want to add\r\n%1%2
as your terms.

Note: The “Stop processing after first hit in file” switch (Options-Search) may be helpful here.

Add Lines to Files