crysalead / dir
递归目录扫描器,用于在文件系统中查找目录和/或文件
2.0.4
2022-05-17 17:12 UTC
Requires
- php: >=5.4
Requires (Dev)
- kahlan/kahlan: ~5.0
README
Dir是一个小型库,允许对目录执行一些递归操作。
Dir::scan()
获取目录中所有嵌套目录和/或文件。
$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()
递归地将目录及其文件复制到目标文件夹中。
$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()
递归地删除目录及其所有内容。
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()
创建嵌套目录。
$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()
创建临时目录(类似于tempnam()
函数,但用于目录)。
$dir = Dir::tempnam(sys_get_temp_dir(), 'mytmp');