Version: 16
restore

Contents

Method

FindAndDelete

ModuleFileContent
LibraryFileContent
Action

Deletes a string from a file.

Parameters

FilePath (string; required): The full path of the file. Environment variables in the form %variable% for windows, and $variable for non-windows operating systems will be expanded.

The FilePath parameter name is only available from v3.2 onwards.

In v3.1 and earlier FileName must be used instead.  While the earlier name will still work, we recommend that, from v3.2 onwards, FilePath is used instead .

FindString (string; required): The search string.

Backup (bool; optional, default false): Whether or not to backup the file prior to any deletions. A copy of the file will be made in the same directory with the .bak suffix. If this already exists, an incremental integer will be added to the filename after the extension. If a backup cannot be created, this method an error will be returned.

CaseSensitive (bool, optional, default true): Whether or not to match case when searching for FindString in the file.

Occurrence (string; optional, default "All"): How the deletion occurs. Valid values are "First", "Last" and "All". "First" will only delete the first occurrence matched, "Last" will only delete the last, and "All" will delete all matches.

Return values

FilePath (string): The full path of the file, with any environment variables expanded.

LineNumber (int): The line number on which a deletion occurred. Lines are split on newline characters.

LineContent(string): The content of the line after a deletion occurred.

BackupFileName (string): The full path of the backup file created if Backup is true. A NULL is returned if Backup is false.

Example

Delete all occurrences of 'covers of queen songs are great!' regardless of case, making a backup of the file before the replacement occurs.

This uses the newer FilePath parameter name. Replace with FileName for v3.1 and older.
@FilePath = "C:\\temp\\Examples\\Example.conf";
@stringToBeRemoved = "AuthenticationPolicy=optional";
FileContent.FindAndDelete(FilePath: @FilePath, FindString: @stringToBeRemoved, Backup:true, CaseSensitive:false, Occurrence:"All");
Platforms
  • Windows
  • Linux
  • MacOS
  • Solaris Intel
  • Solaris SPARC
Notes