Overview

Namespaces

  • Liberty
  • None

Classes

  • BigInteger
  • Block
  • Blockchain
  • Collection
  • CollectionFileList
  • File
  • Folder
  • INI
  • LECDSA
  • Onecrypt
  • SSV
  • Text
  • Transaction
  • Wallet
  • WebPeer
  • Overview
  • Namespace
  • Class

Class Folder

Folder structure browser, lists folders and files.

Provides an Object interface for Common directory related tasks. Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)

Licensed under The MIT License For full copyright and license information, please see the LICENSE.txt Redistributions of files must retain the above copyright notice.

Namespace: Liberty
Copyright: Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
License: MIT License
Since: 0.2.9
Link: http://book.cakephp.org/3.0/en/core-libraries/file-folder.html#folder-api
Located at Liberty/Folder.php
Methods summary
public
# __construct( string|null $path = null, boolean $create = false, integer|boolean $mode = false )

Constructor.

Constructor.

Parameters

$path
Path to folder
$create
Create folder if not found
$mode
Mode (CHMOD) to apply to created folder, false to ignore
public string
# pwd( )

Return current path.

Return current path.

Returns

string
Current path
public string|boolean
# cd( string $path )

Change directory to $path.

Change directory to $path.

Parameters

$path
Path to the directory to change to

Returns

string|boolean
The new path. Returns false on failure
public array
# read( string|boolean $sort = Liberty\Folder::SORT_NAME, array|boolean $exceptions = false, boolean $fullPath = false )

Returns an array of the contents of the current directory. The returned array holds two arrays: One of directories and one of files.

Returns an array of the contents of the current directory. The returned array holds two arrays: One of directories and one of files.

Parameters

$sort

Whether you want the results sorted, set this and the sort property to false to get unsorted results.

$exceptions
Either an array or boolean true will not grab dot files
$fullPath
True returns the full path

Returns

array
Contents of current directory as an array, an empty array on failure
public array
# find( string $regexpPattern = '.*', boolean $sort = false )

Returns an array of all matching files in current directory.

Returns an array of all matching files in current directory.

Parameters

$regexpPattern
Preg_match pattern (Defaults to: .*)
$sort
Whether results should be sorted.

Returns

array
Files that match given pattern
public array
# findRecursive( string $pattern = '.*', boolean $sort = false )

Returns an array of all matching files in and below current directory.

Returns an array of all matching files in and below current directory.

Parameters

$pattern
Preg_match pattern (Defaults to: .*)
$sort
Whether results should be sorted.

Returns

array
Files matching $pattern
protected array
# _findRecursive( string $pattern, boolean $sort = false )

Private helper function for findRecursive.

Private helper function for findRecursive.

Parameters

$pattern
Pattern to match against
$sort
Whether results should be sorted.

Returns

array
Files matching pattern
public static boolean
# isWindowsPath( string $path )

Returns true if given $path is a Windows path.

Returns true if given $path is a Windows path.

Parameters

$path
Path to check

Returns

boolean
true if windows path, false otherwise
public static boolean
# isAbsolute( string $path )

Returns true if given $path is an absolute path.

Returns true if given $path is an absolute path.

Parameters

$path
Path to check

Returns

boolean
true if path is absolute.
public static boolean
# isRegisteredStreamWrapper( string $path )

Returns true if given $path is a registered stream wrapper.

Returns true if given $path is a registered stream wrapper.

Parameters

$path
Path to check

Returns

boolean
True if path is registered stream wrapper.
public static string
# normalizePath( string $path )

Returns a correct set of slashes for given $path. (\ for Windows paths and / for other paths.)

Returns a correct set of slashes for given $path. (\ for Windows paths and / for other paths.)

Parameters

$path
Path to check

Returns

string
Set of slashes ("\" or "/")
public static string
# correctSlashFor( string $path )

Returns a correct set of slashes for given $path. (\ for Windows paths and / for other paths.)

Returns a correct set of slashes for given $path. (\ for Windows paths and / for other paths.)

Parameters

$path
Path to check

Returns

string
Set of slashes ("\" or "/")
public static string
# slashTerm( string $path )

Returns $path with added terminating slash (corrected for Windows or other OS).

Returns $path with added terminating slash (corrected for Windows or other OS).

Parameters

$path
Path to check

Returns

string
Path with ending slash
public static string
# addPathElement( string $path, string|array $element )

Returns $path with $element added, with correct slash in-between.

Returns $path with $element added, with correct slash in-between.

Parameters

$path
Path
$element
Element to add at end of path

Returns

string
Combined path
public boolean
# inPath( string $path, boolean $reverse = false )

Returns true if the Folder is in the given path.

Returns true if the Folder is in the given path.

Parameters

$path
The absolute path to check that the current pwd() resides within.
$reverse
Reverse the search, check if the given $path resides within the current pwd().

Returns

boolean

Throws

InvalidArgumentException
When the given $path argument is not an absolute path.
public boolean
# chmod( string $path, integer|boolean $mode = false, boolean $recursive = true, array $exceptions = [] )

Change the mode on a directory structure recursively. This includes changing the mode on files as well.

Change the mode on a directory structure recursively. This includes changing the mode on files as well.

Parameters

$path
The path to chmod.
$mode
Octal value, e.g. 0755.
$recursive
Chmod recursively, set to false to only change the current directory.
$exceptions
Array of files, directories to skip.

Returns

boolean
Success.
public array
# subdirectories( string|null $path = null, boolean $fullPath = true )

Returns an array of subdirectories for the provided or current path.

Returns an array of subdirectories for the provided or current path.

Parameters

$path
The directory path to get subdirectories for.
$fullPath
Whether to return the full path or only the directory name.

Returns

array
Array of subdirectories for the provided or current path.
public array
# tree( string|null $path = null, array|boolean $exceptions = false, string|null $type = null )

Returns an array of nested directories and files in each directory

Returns an array of nested directories and files in each directory

Parameters

$path
the directory path to build the tree from
$exceptions

Either an array of files/folder to exclude or boolean true to not grab dot files/folders

$type
either 'file' or 'dir'. Null returns both files and directories

Returns

array
Array of nested directories and files in each directory
public boolean
# create( string $pathname, integer|boolean $mode = false )

Create a directory structure recursively.

Create a directory structure recursively.

Can be used to create deep path structures like /foo/bar/baz/shoe/horn

Parameters

$pathname

The directory structure to create. Either an absolute or relative path. If the path is relative and exists in the process' cwd it will not be created. Otherwise relative paths will be prefixed with the current pwd().

$mode
octal value 0755

Returns

boolean
Returns TRUE on success, FALSE on failure
public integer
# dirsize( )

Returns the size in bytes of this Folder and its contents.

Returns the size in bytes of this Folder and its contents.

Returns

integer
size in bytes of current folder
public boolean
# delete( string|null $path = null )

Recursively Remove directories if the system allows.

Recursively Remove directories if the system allows.

Parameters

$path
Path of directory to delete

Returns

boolean
Success
public boolean
# copy( array|string $options )

Recursive directory copy.

Recursive directory copy.

Options

  • to The directory to copy to.
  • from The directory to copy from, this will cause a cd() to occur, changing the results of pwd().
  • mode The mode to copy the files/directories with as integer, e.g. 0775.
  • skip Files/directories to skip.
  • scheme Folder::MERGE, Folder::OVERWRITE, Folder::SKIP
  • recursive Whether to copy recursively or not (default: true - recursive)

Parameters

$options
Either an array of options (see above) or a string of the destination directory.

Returns

boolean
Success.
public boolean
# move( array|string $options )

Recursive directory move.

Recursive directory move.

Options

  • to The directory to copy to.
  • from The directory to copy from, this will cause a cd() to occur, changing the results of pwd().
  • chmod The mode to copy the files/directories with.
  • skip Files/directories to skip.
  • scheme Folder::MERGE, Folder::OVERWRITE, Folder::SKIP
  • recursive Whether to copy recursively or not (default: true - recursive)

Parameters

$options
(to, from, chmod, skip, scheme)

Returns

boolean
Success
public array
# messages( boolean $reset = true )

get messages from latest method

get messages from latest method

Parameters

$reset
Reset message stack after reading

Returns

array
public array
# errors( boolean $reset = true )

get error from latest method

get error from latest method

Parameters

$reset
Reset error stack after reading

Returns

array
public string|boolean
# realpath( string $path )

Get the real path (taking ".." and such into account)

Get the real path (taking ".." and such into account)

Parameters

$path
Path to resolve

Returns

string|boolean
The resolved path
public static boolean
# isSlashTerm( string $path )

Returns true if given $path ends in a slash (i.e. is slash-terminated).

Returns true if given $path ends in a slash (i.e. is slash-terminated).

Parameters

$path
Path to check

Returns

boolean
true if path ends with slash, false otherwise
Constants summary
string MERGE

Default scheme for Folder::copy Recursively merges subfolders with the same name

Default scheme for Folder::copy Recursively merges subfolders with the same name

# 'merge'
string OVERWRITE

Overwrite scheme for Folder::copy subfolders with the same name will be replaced

Overwrite scheme for Folder::copy subfolders with the same name will be replaced

# 'overwrite'
string SKIP

Skip scheme for Folder::copy if a subfolder with the same name exists it will be skipped

Skip scheme for Folder::copy if a subfolder with the same name exists it will be skipped

# 'skip'
string SORT_NAME

Sort mode by name

Sort mode by name

# 'name'
string SORT_TIME

Sort mode by time

Sort mode by time

# 'time'
Properties summary
public string $path

Path to Folder.

Path to Folder.

#
public boolean $sort

Sortedness. Whether or not list results should be sorted by name.

Sortedness. Whether or not list results should be sorted by name.

# false
public integer $mode

Mode to be used on create. Does nothing on windows platforms.

Mode to be used on create. Does nothing on windows platforms.

# 0755
protected array $_fsorts

Functions array to be called depending on the sort type chosen.

Functions array to be called depending on the sort type chosen.

# [ self::SORT_NAME => 'getPathname', self::SORT_TIME => 'getCTime' ]
protected array $_messages

Holds messages from last method.

Holds messages from last method.

# []
protected array $_errors

Holds errors from last method.

Holds errors from last method.

# []
protected array $_directories

Holds array of complete directory paths.

Holds array of complete directory paths.

#
protected array $_files

Holds array of complete file paths.

Holds array of complete file paths.

#
API documentation generated by ApiGen