File helper

File::ls

List files and directories from a specified directory.

Parameters

  • $path (string): Directory path
  • $get_fullpath (bool): Return full path (Default: false)
  • $flag (int): Flags (Default: File::EXCLUDE_BLOCK)
  • $sorting_order (int): Sorting order (Default: SCANDIR_SORT_ASCENDING, see more options).

Returns

  • array

Example

    // List files from '/' and return the list as absolute path
    $files = File::ls('/', true);

    // List files from home directory and exclude block files, directories and hidden files
    $files = File::ls('~', false, File::EXCLUDE_BLOCK | File::EXCLUDE_DIRECTORIES | File::EXCLUDE_HIDDEN);

    // List directories recursively
    $files = File::ls('~', false, File::EXCLUDE_FILES | FILE::LIST_RECURSIVE);

File::exists

Check if file or directory exists. This method allows to search files inside different scopes (Inside or Outside the generated PHAR).

Parameters

  • $path (string): File/Directory path
  • $scope (int): File/Directory scope (Default: Auto, search in local PHAR and/or external filesystem)

Returns

  • bool

Example

    // Check if file exists inside project or PHAR
    File::exists($filename, File::SCOPE_LOCAL);

    // Check if file exists outside the project or PHAR
    File::exists($filename, File::SCOPE_EXTERNAL);

File::home

Returns the executables owner home directory

Returns

  • $string (Path)

Example

    File::home();

File::xcopy

Copy a file, or recursively copy a folder and its contents.

Parameters

  • $source (string): Source path
  • $dest (string): Destination path
  • $permissions (int): Permissions (Default: 0755)
  • $flag (int): Flags

Returns

  • bool

Example

    // Copy recursively an entire directory and exclude the hidden files
    File::xcopy($source_directory, $remote_directory, File::EXCLUDE_HIDDEN);

    // Copy recursively everything inside the source directory 
    File::xcopy($source_directory . '/*', $remote_directory);

File::deltree

Delete a directory recursively

Take care when you this method is used, you can delete files by accident.

Parameters

  • $directory (string): Directory path
  • $recursive (bool): Delete directory recursively (Default: true)
  • $flag (int): Flags

Returns

  • bool