← Back to Documentation

File Operations

Read, write, copy, move, and manage files and directories with simple, cross-platform actions. Works seamlessly on macOS, Linux, and Windows.

Cross-Platform by Design

All file operations use forward slashes (/) in paths, automatically translated on Windows. No platform-specific code needed.

Read / Write

Read and write text, JSON, or binary files.

List / Stat

List directory contents and get file metadata.

Copy / Move

Copy and move files or directories.

Exists / CreateDirectory

Check existence and create directories.

Reading and Writing Files

Read Files

(* Read text file *)
<Read> the <content> from the <file: "./README.md">.

(* Read JSON file - automatically parsed *)
<Read> the <config: JSON> from the <file: "./config.json">.

(* Read binary file *)
<Read> the <image: bytes> from the <file: "./logo.png">.

Write Files

(* Write text - creates parent directories automatically *)
<Write> the <report> to the <file: "./output/report.txt">.

(* Write JSON *)
<Write> the <data: JSON> to the <file: "./export.json">.

Append to Files

(* Append to log file *)
<Append> the <log-line> to the <file: "./logs/app.log">.

Directory Operations

List Directory Contents

(* List all entries *)
<List> the <entries> in the <directory: "./uploads">.

(* Filter with glob pattern *)
<List> the <aro-files> in the <directory: "./src"> matching "*.aro".

(* List recursively *)
<List> the <all-files> in the <directory: "./project"> recursively.

Each entry includes:

Check Existence

(* Check if file exists *)
<Exists> the <found> for the <file: "./config.json">.

when <found> is false {
    <Log> "Config not found!" to the <console>.
}

(* Check if directory exists *)
<Exists> the <dir-exists> for the <directory: "./output">.

Create Directories

(* Create directory with all parent directories *)
<CreateDirectory> the <output-dir> to the <path: "./output/reports/2024">.

Get File Metadata

(* Get detailed file stats *)
<Stat> the <info> for the <file: "./document.pdf">.

<Log> <info: size> to the <console>.
<Log> <info: modified> to the <console>.

Copy and Move

Copy Files

(* Copy a file *)
<Copy> the <file: "./template.txt"> to the <destination: "./copy.txt">.

(* Copy a directory - recursive by default *)
<Copy> the <directory: "./src"> to the <destination: "./backup/src">.

Move and Rename

(* Rename a file *)
<Move> the <file: "./draft.txt"> to the <destination: "./final.txt">.

(* Move to different directory *)
<Move> the <file: "./inbox/report.pdf"> to the <destination: "./archive/report.pdf">.

Complete Example

Here's a complete example that demonstrates file operations:

(Application-Start: File Operations Demo) {
    <Log> "=== File Operations ===" to the <console>.

    (* Check and create output directory *)
    <Exists> the <dir-exists> for the <directory: "./demo-output">.

    when <dir-exists> is false {
        <CreateDirectory> the <output> to the <path: "./demo-output">.
        <Log> "Created directory" to the <console>.
    }

    (* Write a file *)
    <Write> the <content> to the <file: "./demo-output/hello.txt">
        with "Hello from ARO!".

    (* Append to it *)
    <Append> the <line> to the <file: "./demo-output/hello.txt">
        with "\nAppended line.".

    (* Get stats *)
    <Stat> the <info> for the <file: "./demo-output/hello.txt">.
    <Log> "Size: <info: size> bytes" to the <console>.

    (* Copy the file *)
    <Copy> the <file: "./demo-output/hello.txt">
        to the <destination: "./demo-output/hello-copy.txt">.

    (* List directory *)
    <List> the <files> in the <directory: "./demo-output">.

    <Log> "=== Complete ===" to the <console>.
    <Return> an <OK: status> for the <demo>.
}

Actions Reference

Action Description Prepositions
Read Read file contents from
Write Write to file (overwrite) to
Append Append to file to, into
List List directory contents in, from
Stat Get file/directory metadata for
Exists Check existence for
CreateDirectory Create directory to, for
Copy Copy file/directory to
Move Move/rename to
Delete Delete file none

Learn More

See the full file operations specification in ARO-0036: Native File Operations.