kylef / PathKit

Effortless path operations in Swift
BSD 2-Clause "Simplified" License
1.45k stars 169 forks source link

How to add text to the last line of a text file #87

Open iT-Boyer opened 1 year ago

iT-Boyer commented 1 year ago

Consulting chatgpt gives the following tips, but the append method is not found in pathkit:

import PathKit

let path = Path("/path/to/file.txt")
let text = "Hello, PathKit!"

do {
    try path.append(text) //add text to the last line of a text file
} catch let error {
    print(error)
}