Dir is a small library which allows to perform some recursive operations on directories.
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);
}
]
);
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
]
);
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
]
);
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
]
);
Creates a temporary folder (like the tempnam()
function but for directories).
$dir = Dir::tempnam(sys_get_temp_dir(), 'mytmp');