// Writing a file, reading it back, then removing it.
import std.io.println;
import std.fs.write_file;
import std.fs.read_file;
import std.fs.mutation;
def main(): int {
let path: string = "sultanc-example.tmp";
let content: string = "saved by SultanC";
match write_file(&path, &content) with
| result.err(code) -> { println("write failed"); return code; }
| result.ok(_) -> { };
match read_file(&path) with
| result.ok(text) -> { println(text); }
| result.err(code) -> { println("read failed"); return code; };
match remove_file(&path) with
| result.ok(_) -> { println("removed"); }
| result.err(code) -> { return code; };
return 0;
}// كتابة ملف ثم قراءته ثم حذفه.
استورد std.io.println;
استورد std.fs.write_file;
استورد std.fs.read_file;
استورد std.fs.mutation;
عرف الرئيسية(): عدد {
دع المسار: نص = "sultanc-example.tmp";
دع المحتوى: نص = "حفظه السلطان";
طابق اكتب_الملف(&المسار, &المحتوى) مع
| نتيجة.خطأ(الرمز) -> { اطبع_سطر("فشلت الكتابة"); أرجع الرمز; }
| نتيجة.نجح(_) -> { };
طابق اقرأ_الملف(&المسار) مع
| نتيجة.نجح(النص) -> { اطبع_سطر(النص); }
| نتيجة.خطأ(الرمز) -> { اطبع_سطر("فشلت القراءة"); أرجع الرمز; };
طابق أزل_ملفا(&المسار) مع
| نتيجة.نجح(_) -> { اطبع_سطر("حُذف"); }
| نتيجة.خطأ(الرمز) -> { أرجع الرمز; };
أرجع 0;
}
Run it
With the interpreter, without compiling:
./build/sultanc run examples/en/fs/files.snOr compile it to an executable:
./build/sultanc examples/en/fs/files.sn -o build/example && ./build/example