Version 2.4

Filesystem Functions

Nette\Utils\FileSystem is a static class, which contains useful functions for working with file system.

createDir(string $directory, int $mode=0777): void

Creates a $directory if it doesn't exist. Throws an exception Nette\IOException on error occurred.

copy(string $source, string $destination, bool $overwrite=true): void

Copies a file or a directory $source to a $destination. Overwrites existing files and directories by default. If $overwrite is set to false and a $destination already exists, throws an exception Nette\InvalidStateException. Throws an exception Nette\IOException on error occurred.

delete(string $path): void

Deletes a file or a directory specified by $path. Throws an exception Nette\IOException on error occurred.

rename(string $name, string $newName, bool $overwrite=true): void

Renames a file or a directory specified by $name to $newName. Overwrites existing files and directories by default. If $overwrite is set to false and $newName already exists, throws an exception Nette\InvalidStateException. Throws an exception Nette\IOException on error occurred.

write(string $file, string $content, int $mode=0666): void

Writes the $content to a $file. Throws an exception Nette\IOException on error occurred.

read(string $file): string

Reads the content of a $file. Throws an exception Nette\IOException on error occurred.

isAbsolute(string $path): bool

Finds out wheter is a $path absolute or not.

use Nette\Utils\FileSystem;

FileSystem::isAbsolute('../backup'); // false
FileSystem::isAbsolute('/backup'); // true
FileSystem::isAbsolute('C:/backup'); // true