FileHelper

Last updated: August 12th, 2023
Release:

The FileHelper class provides methods for common filesystem operations.

FileHelperGlobs Enum

integer GLOB_ALL Instructs helper to return BOTH files and folders integer GLOB_FOLDERS Instructs helper to return ONLY folders integer GLOB_FILES Instructs helper to return ONLY files

Properties

protected string $relativePath Relative path for this FileHelper instance, replaces '~/' in path strings

Methods

public FileHelper __construct(string $relativePath[, string[] $preIncludes = null]) Instantiates a new FileHelper object, optionally registering files already included in the application public void copyFile(string $source, string $destination) Copies a single file between paths public void copyFolder(string $source, string $destination) Copies an entire folder between paths public bool fileExists(string $path) Determines if a file exists public bool folderExists(string $path) Determines if a folder exists public string getContents(string $path) Retrieves contents of the given file public null|array getFolderFiles(string $path) Retrieves all file names in a folder non-recursively public null|array getFolderFolders(string $path) Retrieves all folder names in a folder non-recursively public null|array getFolderItems(string $path) Retrieves all item names in a folder non-recursively public string getRelativePath() Retrieves the stored relative path protected null|array globFolder(string $path, integer $globType[, bool $recursive = false]) Internal method to traverse a folder's contents and return the requested item types public string load(string $path[, bool $allowReload = false]) Attempts to load file at given path, optionally allowing for file to be loaded more than once public string[] loadGroup(string[] $paths[, bool $allowReload = false]) Attempts to load multiple files, optionally allowing for files to be loaded more than once public bool makeFolder(string $path[, integer $mode = 0777[, bool $recursive = false]]) Attempts to create a folder if it doesn't exist, optional permission mode and recursive toggle public string pathJoin(string $start[, string ...$parts) Joins paths together using UNIX directory separator protected string processRoot(string $path) Internal method to replace '~/' token in a path string public mixed putContents(string $path, mixed $data[, integer $flags = 0[, resource $context = null]]) Attempts to write data to the file given by the path protected void recursiveCopy(string $source, string $dest) Internal method to recursively copy items in a folder public bool removeFile(string $path) Deleted file at the given path public bool removeFolder(string $path) Deletes folder at the given path non-recursively public bool touchFile(string $path[, ?integer $time = null[, ?integer $atime = null]]) Sets access and modification time of file at given path

Further Reading

Next Up

Continue to read about the LogConsoleAppender class, or visit the Table of Contents.