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
deny_folders
Exclude files in comma separated list of folders.
allow_folders
Only include files in comma separated list of folders.
deny_extensions
Exclude file extensions in comma separated list of extensions.
allow_extensions
Only include file extensions in comma separated list of extensions.
include_tempfiles
Include tempfiles. Default false.

Returns

Array array of matching files

Examples

$fs = new FileSystem(); $files = $fs->files("/");

Returns array of all files on system (excluding temp and system files).

Uses

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
deny_folders
Exclude files in comma separated list of folders.
allow_folders
Only allow files in comma separated list of folders.
deny_extensions
Exclude file extensions in comma separated list of extensions.
allow_extensions
Only allow file extensions in comma separated list of extensions.
include_tempfiles
Allow tempfiles. Default false.

Returns

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 ._).

Uses

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

Returns

Boolean true on success, false on error.

Examples

$fs = new FileSystem(); $files = $fs->removeDirRecursively("/");

Deletes your entire disk (don't do this).

Uses

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
delete_tempfiles
Delete tempfiles to empty directories. Default false.

Returns

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).

Uses

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

Returns

Boolean true on success, false on error.

Examples

$fs = new FileSystem(); $files = $fs->makeDirRecursively("/monkeys/fly");

Creates /monkeys/fly structure.

Uses

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

Returns

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.

Uses

PHP
  • is_dir
  • scandir
  • copy
  • is_file
  • dirname
Janitor

none