Skip to main content

Remove a specific line (file.remove_line)

Declaration

ok, removed = file.remove_line(path, n)

Parameters

  • path
    String. Absolute file path.
  • n
    Integer. Line number. 0 means last line + 1. Negative means counting from the end.

Returns

  • ok
    Boolean. true if success, false if failure.
  • removed
    String. The removed line when success; when failed, returns the error message.

Notes

Remove the specified line. If the following lines exist, subsequent lines will move forward.
This function automatically strips UTF-8 BOM at the file head.

Example

local success, line = file.remove_line("/var/mobile/1.txt", 3)
if success then
sys.alert("Success. Removed line: "..line)
else
sys.alert("Failed: "..line)
end

Note: Uses sys.alert