FileSystem
The FileSystem class provides general file system helper functions.
This class is included as default.
Functions
FileSystem::files
Definition
- Name
- files
- Syntax
- Array = FileSystem::files( String $path [, Array $_options ] );
Description
Returns array of files matching the optional criteria specified in $_options located at $path or subfolder of $path.
Parameters
- $path
-
String Path to look for files
- $_options
-
Array Optional options for file matching
Options
Return values
Array array of matching files
Examples
$fs = new FileSystem();
$files = $fs->files("/");
Returns array of all files on system (excluding temp and system files).
Dependencies
PHP
- file_exists
- opendir
- readdir
- closedir
- is_dir
- array_merge
Janitor
none
FileSystem::valid
Definition
- Name
- files
- Syntax
- Boolean = FileSystem::valid( String $file [, Array $_options ] );
Description
Checks if a given file is valid based on the given criteria. Tempfiles and folder references are not valid as default.
Parameters
- $file
-
String Path of file to check validity of
- $_options
-
Array Optional options for file matching
Options
Return values
Boolean true if file is valid, false if not.
Examples
$fs = new FileSystem();
$files = $fs->valid("/file.txt", array("allow_extensions" => "txt"));
Returns true, because file matches the allowed extensions.
$fs = new FileSystem();
$files = $fs->valid("/._tempfile");
Returns false, because file is temp file (starting with ._).
Dependencies
PHP
- count
- basename
- preg_match
- array_intersect
- array_search
- explode
Janitor
none
FileSystem::removeDirRecursively
Definition
- Name
- files
- Syntax
- Boolean = FileSystem::removeDirRecursively( String $path );
Description
Remove directory/folder and nested structure (and delete all files within it).
Parameters
- $path
-
String Path of directory to delete
Return values
Boolean true on success, false on error.
Examples
$fs = new FileSystem();
$files = $fs->removeDirRecursively("/");
Deletes your entire disk (don't do this).
Dependencies
PHP
- basename
- file_exists
- opendir
- is_file
- unlink
- is_dir
- closedir
- rmdir
Janitor
none
FileSystem::removeEmptyDirRecursively
Definition
- Name
- files
- Syntax
- Boolean = FileSystem::removeEmptyDirRecursively( String $path [, Array $_options ] );
Description
Remove directory/folder and nested structure only if it is empty. Can optionally ignore temp-files.
Parameters
- $path
-
String Path of directory to delete
- $_options
-
Array Optional options for file matching
Options
Return values
Boolean true on success, false on error.
Examples
$fs = new FileSystem();
$files = $fs->removeEmptyDirRecursively("/");
Returns false, because the path is not empty (no it isn't).
Dependencies
PHP
- basename
- file_exists
- opendir
- is_file
- unlink
- is_dir
- closedir
- rmdir
- preg_match
Janitor
none
FileSystem::makeDirRecursively
Definition
- Name
- files
- Syntax
- Boolean = FileSystem::makeDirRecursively( String $path );
Description
Create full directory/folder path (creating any missing subfolders if needed).
Parameters
- $path
-
String Path to create in filesystem
Return values
Boolean true on success, false on error.
Examples
$fs = new FileSystem();
$files = $fs->makeDirRecursively("/monkeys/fly");
Creates /monkeys/fly structure.
Dependencies
PHP
- file_exists
- explode
- count
- mkdir
Janitor
none
FileSystem::copy
Definition
- Name
- files
- Syntax
- Boolean = FileSystem::copy( String $path , String $dest );
Description
Copies directory/folder and all content to new destination. Creates destination path if needed.
Parameters
- $path
-
String Path to copy
- $dest
-
String Destination to copy to
Return values
Boolean true on success, false on error.
Examples
$fs = new FileSystem();
$files = $fs->copy("/hello", "/goodbye");
Creates /goodbye and copies content from /hello into /goodbye.
Dependencies
PHP
- is_dir
- scandir
- copy
- is_file
- dirname
Janitor
none