Skip to main content

1E 8.1 (on-premises)

FileContent.FindAndDelete

Method

FindAndDelete

Module

FileContent

Library

FileContent

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.

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.

@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

Notes