Skip to content
CShift0.32

File

Struct · namespace System

struct File

Whole files: reading, writing, copying, moving and deleting them (static functions). The paths are passed to the C library as they are; text is UTF-8 unless an Encoding is given.

var text = try File.ReadAllText("config.txt");
try File.WriteAllText("out.txt", text + "\n");
Name Description
Exists Whether a file (or directory) exists at path.
Delete Deletes the file at path.
ReadAllBytes The contents of a file as bytes.
ReadAllText The contents of a UTF-8 text file.
WriteAllBytes Creates the file or replaces its contents with bytes.
Copy Copies a file; an existing target is replaced only with overwrite.
Move Moves (renames) a file; an existing target is replaced only with overwrite.
GetLastWriteTime When the file was last written, in local time.
GetLastWriteTimeUtc When the file was last written, in UTC.
SetLastWriteTime Sets when the file (or folder) was last written; a local time is converted to UTC.
SetLastWriteTimeUtc Sets when the file (or folder) was last written, in UTC (a local time is converted).
WriteAllText Creates the file or replaces its contents with text (UTF-8).
static bool Exists(StringSlice path)

Whether a file (or directory) exists at path.

static IoError<void> Delete(StringSlice path)

Deletes the file at path.

Errors

static IoError<uint8[]> ReadAllBytes(StringSlice path)

The contents of a file as bytes.

Errors

static IoError<string> ReadAllText(StringSlice path)

The contents of a UTF-8 text file. A leading byte order mark is removed.

Errors

static IoError<string> ReadAllText(StringSlice path, Encoding encoding)

The contents of a text file in encoding. A leading UTF-8 byte order mark is removed.

Errors

static IoError<void> WriteAllBytes(StringSlice path, ReadOnlySlice<uint8> bytes)

Creates the file or replaces its contents with bytes.

Errors

static IoError<void> Copy(StringSlice source, StringSlice target, bool overwrite)

Copies a file; an existing target is replaced only with overwrite.

Errors

Since 0.04

static IoError<void> Copy(StringSlice source, StringSlice target)

Copies a file; an existing target is not replaced.

Errors

Since 0.04

static IoError<void> Move(StringSlice source, StringSlice target, bool overwrite)

Moves (renames) a file; an existing target is replaced only with overwrite.

Errors

Since 0.19

static IoError<void> Move(StringSlice source, StringSlice target)

Moves (renames) a file; an existing target is not replaced.

Errors

Since 0.19

static IoError<DateTime> GetLastWriteTime(StringSlice path)

When the file was last written, in local time.

Errors

Since 0.19

static IoError<DateTime> GetLastWriteTimeUtc(StringSlice path)

When the file was last written, in UTC.

Errors

Since 0.19

static IoError<void> SetLastWriteTime(StringSlice path, DateTime time)

Sets when the file (or folder) was last written; a local time is converted to UTC. On POSIX systems the time of the last access is set too.

Errors

Since 0.29

static IoError<void> SetLastWriteTimeUtc(StringSlice path, DateTime time)

Sets when the file (or folder) was last written, in UTC (a local time is converted).

Errors

Since 0.29

static IoError<void> WriteAllText(StringSlice path, StringSlice text)

Creates the file or replaces its contents with text (UTF-8).

Errors

static IoError<void> WriteAllText(StringSlice path, StringSlice text, Encoding encoding)

Creates the file or replaces its contents with text in encoding.

Errors