Mecha CMS

Deep learning on using the API.

Class Folder

Author: Taufik Nurrohman · 94 Views

Tweet

Working with folders.

Table of Content

Exist 

Check the existence of a folder.

Folder::exist($input, $fail = false);

Example:

if (Folder::exist('path\to\folder')) {
    echo 'Folder `path\to\folder` is exists.';
}

Return the given path if folder is exists, return false if not:

if ($folder = Folder::exist('path\to\folder')) {
    define('THE_FOLDER', $folder);
} else {
    define('THE_FOLDER', 'path\to\folder.legacy');
}

Shortcut:

define('THE_FOLDER', Folder::exist('path\to\folder', 'path\to\folder.legacy'));

Loop through list of folder path until it finds a folder that is exists:

if ($test = Folder::exist([
    'page-post-2016',
    'page-post',
    'page'
], false)) {
    echo $test . ' does exist.';
} else {
    echo $test . ' is now `false`.';
}

Set 

Create a folder.

Folder::set($input, $consent = 0777);

Example:

Folder::set('foo\bar\baz');

Set custom folder permission:

Folder::set('foo\bar\baz', 0700);

Consent 

Set folder permission.

Folder::open('path\to\folder')->consent(0600);

Size 

Count the total sizes of files in a folder.

Folder::size($folder, $unit = null, $prec = 2);

Example:

echo Folder::size('path\to\folder');

Related: Class File

0 Comments

No comments yet.