PHPackages                             alexya-framework/filesystem - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. alexya-framework/filesystem

ActiveFramework[Framework](/categories/framework)

alexya-framework/filesystem
===========================

Alexya's FileSystem utilities

3.0.4(9y ago)0902GNUPHPPHP &gt;=7.0

Since Aug 13Pushed 9y ago1 watchersCompare

[ Source](https://github.com/AlexyaFramework/FileSystem)[ Packagist](https://packagist.org/packages/alexya-framework/filesystem)[ RSS](/packages/alexya-framework-filesystem/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (7)Used By (2)

FileSystem
==========

[](#filesystem)

Alexya's filesystem components

Contents
--------

[](#contents)

- [File Operations](#file_operations)
    - [Instancing File Objects](#instancing_file_objects)
    - [File permissions](#file_permissions)
    - [File information](#file_information)
    - [Reading/Writing to a file](#reading_writing_to_a_file)
- [Directory Operations](#directory_operations)
    - [Instancing Directory Objects](#instancing_irectory_objects)
    - [Directory files](#irectory_files)
    - [Directory subdirectories](#irectory_subdirectories)
    - [Directory information](#irectory_information)

File Operations
---------------

[](#file-operations)

Reading/Writing to a file is really easy with the class `\Alexya\FileSystem\File`.

### Instancing File objects

[](#instancing-file-objects)

The constructor accepts as parameter the path to the file that will be used for I/O operations, if the file doesn't exist it will throw an exception of type `\Alexya\FileSystem\Exceptions\FileDoesntExist`.

You can check if a file exists with the method `\Alexya\FileSystem\File::exists` which accepts as parameter the path to the file and returns `true` if the path exists and is a file (or `false` if it doesn't).

To make a file use the method `\Alexya\FileSystem\File::make` which accepts as parameter the path to the file that will be created and returns an instance of the file object. If the file already exists it will throw an exception of type `\Alexya\FileSystem\Exceptions\FileAlreadyExists`, however, you can change this behavior with the second parameter that is an integer and tells what to do if the path already exists:

- `\Alexya\FileSystem\File::MAKE_FILE_EXISTS_THROW_EXCEPTION`: throws an exception (default).
- `\Alexya\FileSystem\File::MAKE_FILE_EXISTS_OVERWRITE`: deletes the file and recreates it.
- `\Alexya\FileSystem\File::MAKE_FILE_EXISTS_OPEN`: opens the file.

Example:

```
