FileSystem
final class FileSystem
File system tool.
Methods
Creates a directory if it does not exist, including parent directories.
Copies a file or an entire directory. Overwrites existing files and directories by default.
Opens file and returns resource.
Deletes a file or an entire directory if exists. If the directory is not empty, it deletes its contents first.
Renames or moves a file or a directory. Overwrites existing files and directories by default.
Reads the content of a file.
Reads the file content line by line. Because it reads continuously as we iterate over the lines, it is possible to read files larger than the available memory.
Writes the string to a file.
Sets file permissions to $fileMode
or directory permissions to $dirMode
.
Determines if the path is absolute.
Normalizes ..
and .
and directory separators in path.
Joins all segments of the path and normalizes the result.
Converts backslashes to slashes.
Converts slashes to platform-specific directory separators.
Details
at line 24
static void
createDir(string $dir, int $mode = 0777)
Creates a directory if it does not exist, including parent directories.
at line 42
static void
copy(string $origin, string $target, bool $overwrite = true)
Copies a file or an entire directory. Overwrites existing files and directories by default.
at line 82
static resource
open(string $path, string $mode)
Opens file and returns resource.
at line 100
static void
delete(string $path)
Deletes a file or an entire directory if exists. If the directory is not empty, it deletes its contents first.
at line 132
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.
at line 162
static string
read(string $file)
Reads the content of a file.
at line 183
static Generator
readLines(string $file, bool $stripNewLines = true)
Reads the file content line by line. Because it reads continuously as we iterate over the lines, it is possible to read files larger than the available memory.
at line 212
static void
write(string $file, string $content, int|null $mode = 0666)
Writes the string to a file.
at line 239
static void
makeWritable(string $path, int $dirMode = 0777, int $fileMode = 0666)
Sets file permissions to $fileMode
or directory permissions to $dirMode
.
Recursively traverses and sets permissions on the entire contents of the directory as well.
at line 272
static bool
isAbsolute(string $path)
Determines if the path is absolute.
at line 281
static string
normalizePath(string $path)
Normalizes ..
and .
and directory separators in path.
at line 302
static string
joinPaths(string ...$paths)
Joins all segments of the path and normalizes the result.
at line 311
static string
unixSlashes(string $path)
Converts backslashes to slashes.
at line 320
static string
platformSlashes(string $path)
Converts slashes to platform-specific directory separators.