toolkit

Dir

Directory helpers: list, create, move and delete folders.

Dir:: Phlat\Toolkit\Dir 17 methods

Inspection 4

  • exists Whether the directory exists.
  • isEmpty Whether the directory holds nothing.
  • isReadable Whether the directory can be read.
  • isWritable Whether the directory can be written to.

Path 3

  • name Returns the final segment of the path.
  • parent Returns the parent directory. $levels controls how many levels up.
  • resolve Resolves symlinks and normalizes . and .. - returns null if the path does not exist.

Contents 4

  • list Returns all entry names (files and dirs) excluding . and ..
  • files Returns full paths of files directly inside $path.
  • filesRecursive Returns full paths of every file beneath $path, subfolders included.
  • directories Returns full paths of subdirectories directly inside $path.

Operations 6

  • make Creates the directory.
  • delete Deletes an empty directory.
  • deleteRecursive Deletes a directory and all its contents recursively.
  • move Moves or renames a directory.
  • copy Copies a directory and all its contents recursively.
  • stat The number of files under a directory, symlinks counted but not followed, and their size in bytes - what copy() would copy, given the same $skip.

Inspection

Dir::exists(string $path): bool

Whether the directory exists.

Parameters (1)
$path string

Returns bool

phlat/src/Toolkit/Dir.php:17
Dir::isEmpty(string $path): bool

Whether the directory holds nothing.

Parameters (1)
$path string

Returns bool

phlat/src/Toolkit/Dir.php:23
Dir::isReadable(string $path): bool

Whether the directory can be read.

Parameters (1)
$path string

Returns bool

phlat/src/Toolkit/Dir.php:41
Dir::isWritable(string $path): bool

Whether the directory can be written to.

Parameters (1)
$path string

Returns bool

phlat/src/Toolkit/Dir.php:47

Path

Dir::name(string $path): string

Returns the final segment of the path.

Parameters (1)
$path string

Returns string

phlat/src/Toolkit/Dir.php:55
Dir::parent(string $path, int $levels = 1): string

Returns the parent directory. $levels controls how many levels up.

Parameters (2)
$path string
$levels int = 1

Returns string

phlat/src/Toolkit/Dir.php:61
Dir::resolve(string $path): ?string

Resolves symlinks and normalizes . and .. - returns null if the path does not exist.

Parameters (1)
$path string

Returns ?string

phlat/src/Toolkit/Dir.php:67

Contents

Dir::list(string $path): array

Returns all entry names (files and dirs) excluding . and ..

Parameters (1)
$path string

Returns array

phlat/src/Toolkit/Dir.php:76
Dir::files(string $path): array

Returns full paths of files directly inside $path.

Parameters (1)
$path string

Returns array

phlat/src/Toolkit/Dir.php:89
Dir::filesRecursive(string $path): array

Returns full paths of every file beneath $path, subfolders included.

Parameters (1)
$path string

Returns array

phlat/src/Toolkit/Dir.php:99
Dir::directories(string $path): array

Returns full paths of subdirectories directly inside $path.

Parameters (1)
$path string

Returns array

phlat/src/Toolkit/Dir.php:108

Operations

Dir::make(string $path, int $permissions = 493): bool

Creates the directory.

Recursive and idempotent by default.

Parameters (2)
$path string
$permissions int = 493

Returns bool

phlat/src/Toolkit/Dir.php:120
Dir::delete(string $path): bool

Deletes an empty directory.

Parameters (1)
$path string

Returns bool

phlat/src/Toolkit/Dir.php:126
Dir::deleteRecursive(string $path): bool

Deletes a directory and all its contents recursively.

Symlinks are unlinked, never followed.

Parameters (1)
$path string

Returns bool

phlat/src/Toolkit/Dir.php:132
Dir::move(string $source, string $destination): bool

Moves or renames a directory.

Parameters (2)
$source string
$destination string

Returns bool

phlat/src/Toolkit/Dir.php:146
Dir::copy(string $source, string $destination, ?callable $skip = null, ?callable $copied = null): void

Copies a directory and all its contents recursively.

Symlinks are recreated as symlinks, never dereferenced. $skip, given each source path, returns true to leave that file or folder out; $copied is given the source path of each file or symlink once it is copied.

Parameters (4)
$source string
$destination string
$skip ?callable = null
$copied ?callable = null
phlat/src/Toolkit/Dir.php:152
Dir::stat(string $path, ?callable $skip = null): array

The number of files under a directory, symlinks counted but not followed, and their size in bytes - what copy() would copy, given the same $skip.

Parameters (2)
$path string
$skip ?callable = null

Returns array

phlat/src/Toolkit/Dir.php:179