delete_line_from_file

delete_line_from_file($file,$line,$timeout=COMMAND_TIME); - delete the specified line in the file, available from version 7.0.4

The function accepts parameters as input:

  • $file – path to the file to delete the line in. It can be either absolute or relative (relative to the script folder).
  • $line – the number of the line to delete in the file (starts with 0)
  • $timeout – the maximum time to perform this operation (in seconds), by default - 60 seconds, if the operation is not completed during this time, the script continues to run further.

    After testing, the function returns the result of its work to the script :
  • true – operation completed (boolean)
  • false – operation failed (boolean)

    PHP example: textfile->".basename(__FILE__)."
    "; //prepare files $path = "test \ test_delete.txt"; $file_os->delete($path); $file_os->copy("test \ test_dedupe.txt", $path); //1 echo("1.Get the number of lines in the file:"); echo $textfile->get_lines_count($path)." n"; //2 echo("2.Remove line from file:"); echo $textfile->delete_line_from_file($path, 2)." n"; //3 echo("3.Get the number of lines in the file:"); echo $textfile->get_lines_count($path)." n"; //end echo "

    "; //Quit $app->quit(); ?>
    Python example: # Additional paths import sys sys.path.insert(0, '../../../Templates PY/') xhe_host = "127.0.0.1:7016" from xweb_human_emulator import * # Start echo("
    textfile.xxxxxxxxx
    ") # prepare files path = "test \ test_delete.txt"; file_os.delete(path); file_os.copy("test \ test_dedupe.txt", path); # 1 echo("1.Get the number of lines in the file:"); echo(textfile.get_lines_count(path), " "); # 2 echo("2.Remove line from file:"); echo(textfile.delete_line_from_file(path, 2), " "); # 3 echo("3.Get the number of lines in the file:"); echo(textfile.get_lines_count(path), " "); # end echo("

    ") # Quit app.quit()
    C# example: #region using using System; using System.Diagnostics; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Threading; using XHE; using XHE.XHE_DOM; using XHE.XHE_System; using XHE.XHE_Window; using XHE.XHE_Web; #endregion class Program: XHEScript { static void Main(string [] args) { //init XHE server = "127.0.0.1:7016"; InitXHE(); //Start echo("
    textfile.get_all_external_inner_texts_and_hrefs
    "); //prepare files string path = "test \ test_delete.txt"; file_os.delete(path); file_os.copy("test \ test_dedupe.txt", path); //1 echo("1.Get the number of lines in the file:"); echo(textfile.get_lines_count(path) + " n"); //2 echo("2.Remove line from file:"); echo(textfile.delete_line_from_file(path, 2) + " n"); //3 echo("3.Get the number of lines in the file:"); echo(textfile.get_lines_count(path) + " n"); //end echo("

    "); app.quit(); } }
    Java Script example: //connect the object to control the emulator, if not already connected xhe_host = "127.0.0.1:7016"; echo = require("../../../Templates JS/xweb_human_emulator.js"); //Start echo("
    textfile.get_line_from_file
    "); //prepare files var path = "test \ test_delete.txt"; file_os.delete(path); file_os.copy("test \ test_dedupe.txt", path); //1 echo("1.Get the number of lines in the file:"); echo(textfile.get_lines_count(path) + " n"); //2 echo("2.Remove line from file:"); echo(textfile.delete_line_from_file(path, 2) + " n"); //3 echo("3.Get the number of lines in the file:"); echo(textfile.get_lines_count(path) + " n"); //end echo("

    "); //Quit app.quit();