Dz
Djazair
v1.0.5
🔍

File Module

Import using: use file

Read & Write Operations

  • file.read(path) - Read entire file as string.
  • file.readLines(path) - Read file as array of lines.
  • file.readBytes(path) - Read file as byte array (0-255).
  • file.write(path, text) - Write text, replacing existing content. Returns True.
  • file.writeBytes(path, data) - Write byte array in binary mode. Returns True.
  • file.writeLines(path, lines) - Write array of lines, each followed by newline. Returns True.
  • file.append(path, text) - Append text to end of file. Returns True.
  • file.appendLines(path, lines) - Append lines to file. Returns True.
  • file.truncate(path, size) - Truncate file to given byte size. Returns True.
use file
# Write and read text
file.write("sample.txt", "Hello World\nLine 2")
let data = file.read("sample.txt")
print(data)
let lines = file.readLines("sample.txt")
print(str(lines.length()))  # 2

# Binary read/write
file.writeBytes("data.bin", [72, 101, 108])
let bytes = file.readBytes("data.bin")
print(str(bytes))  # [72, 101, 108]

# Append
file.append("sample.txt", "\nAppended line")

# WriteLines
file.writeLines("lines.txt", ["a", "b", "c"])

Advanced File Controls (FileHandle)

Open files using file.open(path, mode) to get a stream object: Modes are "r", "w", "a", "rb", "wb":

use file
let handle = file.open("output.dat", "w")
handle.write("Raw data stream")
handle.flush()
handle.close()

File Manipulation

  • file.create(path) - Create empty file. Returns True.
  • file.copy(src, dest) - Copy file. Returns True.
  • file.move(src, dest) - Move/rename file. Returns True.
  • file.rename(old, new) - Rename file (alias for move).
  • file.delete(path) - Delete file. Returns True.
  • file.symlink(target, linkpath) - Create symbolic link. Returns True.
  • file.readlink(path) - Read symlink target (string or Null).
use file
file.create("newfile.txt")
file.copy("newfile.txt", "copy.txt")
file.rename("copy.txt", "renamed.txt")
print(str(file.exists("renamed.txt")))  # True
file.delete("renamed.txt")
file.delete("newfile.txt")

Status Query

  • file.exists(path) - Check path presence.
  • file.isDir(path) - Returns True if target is directory.
  • file.isFile(path) - Returns True if target is regular file.
  • file.size(path) - File size in bytes.
  • file.modified(path) - Last modification timestamp (Unix epoch seconds).
  • file.permissions(path) - File permission mode (numeric).
  • file.stat(path) - Complete stat Map (size, mtime, mode, isFile, isDir, etc.).
  • file.chmod(path, mode) - Change permission mode. Returns True.
use file
file.write("test.txt", "content")
print(str(file.exists("test.txt")))     # True
print(str(file.isFile("test.txt")))     # True
print(str(file.isDir("test.txt")))      # False
print(str(file.size("test.txt")))       # 7
let s = file.stat("test.txt")
print(s["size"])  # 7
file.delete("test.txt")
© 2026 Harizi Riyadh. Released under the MIT License.
Official Website for Djazair.