Recursive directory scanner to locate directories and/or files in a file system

Maintainers

👁 jails

Package info

github.com/crysalead/dir

pkg:composer/crysalead/dir

Statistics

Installs: 221 452

Dependents: 8

Suggesters: 0

Stars: 13

Open Issues: 0

2.0.4 2022-05-17 17:12 UTC

Requires

  • php: >=5.4

Requires (Dev)

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT 0390ac74a8f1634b1ec1adffdd118125f1271976

filedirectoryfile systemDirectory Scanner

This package is auto-updated.

Last update: 2026-06-18 01:59:58 UTC


README

👁 Build Status
👁 Code Coverage

Dir is a small library which allows to perform some recursive operations on directories.

Dir::scan()

Gets all nested directories and/or files present inside a directory.

$files = Dir::scan('my/dir', // Can be a string path of an array of string paths
 [
 'include' => '*.txt', // Can be an array of includes
 'exclude' => '*.save.txt', // Can be an array of excludes
 'type' => 'file' // Can be an array of types, possible values:
 // `'file'`, `'dir'`, `'executable'`, `'link'`, `'readable'`, `'writable'`
 'skipDots' => true, // Keeps '.' and '..' directories in result
 'leavesOnly' => true, // Keeps only leaves
 'followSymlinks' => true, // Follows Symlinks
 'recursive' => true // Scans recursively,
 'copyHandler' => function($path, $target) { // The copy handler
 copy($path, $target);
 }
 ]
);

Dir::copy()

Copies a directory with files recursively into a destination folder.

$files = Dir::copy('my/dir', // A string path of an array of string paths
 'my/destination', // A destination path (string only)
 [
 'mode' => 0755, // Mode used for directory creation
 'childrenOnly' => false, // Copies the file inside 'my/dir' if `true`, otherwise `dir` will be
 // added as the root directory.
 'followSymlinks' => true, // Follows Symlinks
 'recursive' => true // Scans recursively
 ]
);

Dir::remove()

Removes a directory and all its content recursively.

Dir::remove('my/dir', // Can be a string path of an array of string paths
 [
 'followSymlinks' => false, // Follows Symlinks
 'recursive' => true, // Scans recursively
 'include' => '*.txt', // Can be an array of includes
 'exclude' => '*.save.txt', // Can be an array of excludes
 ]
);

Dir::make()

Makes nested directories.

$success = Dir::make('my/dir', // Can be a string path of an array of string paths
 [
 'mode' => 0755, // Mode used for directory creation
 'recursive' => true, // Scans recursively
 'include' => '*.txt', // Can be an array of includes
 'exclude' => '*.save.txt', // Can be an array of excludes
 ]
);

Dir::tempnam()

Creates a temporary folder (like the tempnam() function but for directories).

$dir = Dir::tempnam(sys_get_temp_dir(), 'mytmp');