TLang.File
TLang.File provides file I/O operations. All paths are relative to the project root (where manifest.yml lives). Parent directories are created automatically on write.
use TLang.File
Writing Files
File.write has two modes depending on whether the third argument is provided. Scaffold-once — omit the third argument. The file is written only if it does not already exist. Use this for boilerplate that the user will edit.
File.write("src/App.kt", content) // write once, skip if exists
Always overwrite — pass true as the third argument. Use this for fully generated files that should never be manually edited.
File.write("generated/User.kt", content, true) // always regenerate
Reading Files
let content = File.read("config/settings.json") // → String
Checking Existence
let ok = File.exists("config/settings.json") // → Bool
if (!File.exists("output/")) {
File.createDir("output/")
}
Modifying Existing Files
Search and replace a substring in an existing file.
File.searchReplace("src/Config.kt", "OLD_VALUE", "NEW_VALUE")
Append content to the end of a file.
File.append("logs/build.log", "Build complete\n")
Insert content after the first occurrence of a pattern.
File.appendAfter("src/routes.ts", "// routes", newRoute)
Insert content before the first occurrence of a pattern.
File.prependBefore("src/index.ts", "export default app", banner)
Directories
File.createDir("output/generated") // create (including parents)
File.deleteDir("output/tmp") // delete recursively
File.deleteFile("output/old.kt") // delete a file
Usage Patterns
Scaffold then generate — write the boilerplate once, then always overwrite the generated parts.
// Boilerplate that the user edits — write once
File.write("src/main/kotlin/App.kt", appShell)
// Fully generated — always overwrite
File.write("src/main/kotlin/UserRepository.kt", repoCode, true)
Check-then-write — vary behaviour on first vs subsequent runs.
if (File.exists("config/settings.json")) {
// subsequent run — patch instead of replace
File.searchReplace("config/settings.json", oldVersion, newVersion)
} else {
// first run — scaffold
File.write("config/settings.json", defaultConfig)
}
Read-transform-write — read an existing file, transform it, write it back.
let original = File.read("src/routes.ts")
let updated = String.replace(original, "v1", "v2")
File.write("src/routes.ts", updated, true)