ModifyFile |
Top Previous Next |
The ModifyFile command allows you to replace specific text in a specified text file with alternative text, and optionally output the modified text to a new file. Important: This command actions the substitution assignments assigned to the Subs list by prior commands in the current User section using one or more Subs commands. Those Substitution assignments can be used by an unlimited number of ModifyFile commands within the same User section. Command Syntax
ModifyFile:[SourceFileName],[TargetFileName]
The colon after the command is compulsory. The comma between parameters is compulsory if you provide a second parameter, otherwise it can be ignored. Any additional spaces or characters will cause an error to be thrown. The command itself is not case sensitive, but parameters may be depending on the operating system and locale.
Parameters:
SourceFileName: The fully qualified path and file name identifying the file to update. TargetFileName: The fully qualified path and file name to which the updated file should be saved
The SourceFileName parameter is compulsory, the TargetFileName parameter optional. If the TargetFileName parameter is not provided, the source file will be overwritten once modified. The parameters must be surrounded by quotation marks if one or more spaces are included in the path and file name. It is good practice to include the quotation marks in any case, so that it reduces the risk of error when writing scripts. Note: It is permissible for the Source and Target file names to be the same. In that situation the file modification will be written to a temporary file in case an error occurs during processing. If the processing succeeds, the original file will be deleted and the temporary file renamed to the original file name. Examples:
Single file substitution to a different file:
ModifyFile:"C:\Test Text.txt","C:\Test Text (updated).txt"
Single file substitution overwriting the existing file:
ModifyFile:"C:\Test Text.txt"
See Also: Subs RegexReplace |