change-file-lines ( ..a path encoding quot: ( ..a seq -- ..b seq' ) -- ..b )
Factor handbook » Input and output » Reading and writing files

Prev:set-file-lines ( seq path encoding -- )
Next:with-file-reader ( path encoding quot -- )


Vocabulary
io.files

Inputs
patha pathname string
encodingan encoding descriptor
quota quotation


Outputs
None

Word description
Reads the file lines, transforms the file lines, and writes them back to the same file name. Preserves the original line separators by position and whether the final line has a separator. Additional line separators use the first separator found in the file, or LF if there are none. An empty transformation preserves the text, including mixed line endings.

Errors
Throws an error if the file cannot be opened for writing.

See also
set-file-lines, file-lines, set-file-contents, file-contents, change-file-contents

Definition


:: change-file-lines
( ..a path encoding quot: ( ..a seq -- ..b seq' ) -- ..b )
path encoding file-contents
file-line-endings :> ( lines endings ) lines quot call
path encoding
[ endings write-file-line-endings ] with-file-writer ;
inline