Filesystem Package provide a fluent, object-oriented interface for working with filesystem.
Installation
composer require glowy/filesystem
Usage
use Glowy\Filesystem\Filesystem;
// Create a Filesystem instance.
$filesystem = new Filesystem();
// Using global helper function filesystem()
$filesystem = filesystem();
Extending
Filesystem are "macroable", which allows you to add additional methods to the Filesystem class at run time. For example, the following code adds a customMethod method to the Filesystem class:
use Glowy\Filesystem\Filesystem;
use Glowy\Filesystem\Directory;
use Glowy\Filesystem\File;
use Glowy\Macroable\Macroable;
Filesystem::macro('countFiles', function($path) {
return count(iterator_to_array($this->find()->in($path)->files(), false));
});
$filesytem = new Filesystem();
echo $filesytem->countFiles('/directory');
The above example will output:
1
Methods
Filesystem
| Method |
Description |
| directory |
Create a Directory instance. |
| file |
Create a File instance. |
| find |
Create a File instance. |
| glob |
Find path names matching a given pattern. |
| isAbsolute |
Determine if the given path is absolute path. |
| isStream |
Determine if the given path is a stream path. |
| isWindowsPath |
Determine if the given path is absolute path. |
File
| Method |
Description |
| append |
Append to a file. |
| basename |
Get the trailing name component from a file path. |
| chmod |
Get/Set UNIX mode of a file. |
| copy |
Copy a file to a new location. |
| delete |
Delete the file at a given path. |
| exists |
Checks the existence of file and returns false if any of them is missing. |
| extension |
Get the file extension from a file path. |
| get |
Get the contents of a file. |
| hash |
Get the MD5 hash of the file at the given path. |
| isFile |
Determine if the given path is a regular file. |
| isReadable |
Determine if the given path is readable. |
| isWritable |
Determine if the given path is writable. |
| lastAccess |
Get the file's last access time. |
| lastModified |
Get the file's last modification time. |
| mimeType |
Get the mime-type of a given file. |
| move |
Move a file to a new location. |
| name |
Get the file name from a file path. |
| path |
Return current path. |
| prepend |
Prepend to a file. |
| put |
Write the contents of a file. |
| sharedGet |
Get contents of a file with shared access. |
| size |
Gets file size in bytes. |
| type |
Get the file type of a given file. |
Directory
| Method |
Description |
| chmod |
Get/Set UNIX mode of a directory. |
| clean |
Empty the specified directory of all files and directories. |
| copy |
Copy a directory from one location to another. |
| create |
Create a directory. |
| delete |
Delete a directory. |
| exists |
Checks the existence of directory and returns false if any of them is missing. |
| isDirectory |
Determine if the given path is a directory. |
| move |
Move a directory. |
| path |
Return current path. |
| size |
Gets size of a given directory in bytes. |