class FileSystem

File system tool.

Traits

Static class.

Methods

static void
createDir(string $dir, int $mode = 0777)

Creates a directory if it doesn't exist.

static void
copy(string $origin, string $target, bool $overwrite = true)

Copies a file or a directory. Overwrites existing files and directories by default.

static void
delete(string $path)

Deletes a file or directory if exists.

static void
rename(string $origin, string $target, bool $overwrite = true)

Renames or moves a file or a directory. Overwrites existing files and directories by default.

static string
read(string $file)

Reads the content of a file.

static void
write(string $file, string $content, int|null $mode = 0666)

Writes the string to a file.

static bool
isAbsolute(string $path)

Determines if the path is absolute.

static string
normalizePath(string $path)

Normalizes `.

static string
joinPaths(string ...$paths)

Joins all segments of the path and normalizes the result.

Details

at line 26
static void createDir(string $dir, int $mode = 0777)

Creates a directory if it doesn't exist.

Parameters

string $dir
int $mode

Return Value

void

Exceptions

IOException on error occurred

at line 39
static void copy(string $origin, string $target, bool $overwrite = true)

Copies a file or a directory. Overwrites existing files and directories by default.

Parameters

string $origin
string $target
bool $overwrite

Return Value

void

Exceptions

IOException on error occurred
InvalidStateException if $overwrite is set to false and destination already exists

at line 73
static void delete(string $path)

Deletes a file or directory if exists.

Parameters

string $path

Return Value

void

Exceptions

IOException on error occurred

at line 97
static void rename(string $origin, string $target, bool $overwrite = true)

Renames or moves a file or a directory. Overwrites existing files and directories by default.

Parameters

string $origin
string $target
bool $overwrite

Return Value

void

Exceptions

IOException on error occurred
InvalidStateException if $overwrite is set to false and destination already exists

at line 121
static string read(string $file)

Reads the content of a file.

Parameters

string $file

Return Value

string

Exceptions

IOException on error occurred

at line 135
static void write(string $file, string $content, int|null $mode = 0666)

Writes the string to a file.

Parameters

string $file
string $content
int|null $mode

Return Value

void

Exceptions

IOException on error occurred

at line 150
static bool isAbsolute(string $path)

Determines if the path is absolute.

Parameters

string $path

Return Value

bool

at line 159
static string normalizePath(string $path)

Normalizes `.

.and.` and directory separators in path.

Parameters

string $path

Return Value

string

at line 179
static string joinPaths(string ...$paths)

Joins all segments of the path and normalizes the result.

Parameters

string ...$paths

Return Value

string