Vesthelm Engine

2.1.4 User Guide

Folder Class

The Folder class provides directory functions.

Calling the Folder Class

$Folder = $this->Folder;

Creating Directories Recursively

$this->Folder->mkdir_r("/path/to/my/dir");

The second argument the mode consists of three octal number components specifying access restrictions for the owner, the user group in which the owner is in, and to everybody else in this order.

Creating index.html file in each folder:

$this->Folder->mkdir_r("/path/to/my/dir", 0777, true);

Returns TRUE on success or FALSE on failure.

Removing Directory

$this->Folder->remove("/path/to/my/dir");

Returns TRUE on success or FALSE on failure.

Removing Directories and Files Recursively

$this->Folder->rmdir_r("/path/to/my/dir");
or
$this->Folder->removeAll("/path/to/my/dir");

Returns TRUE on success or FALSE on failure.

Getting Directory Files

In directory compile_dir/log there are 2 files: .htaccess and index.html to get files:

$files = $this->Folder->getFiles("/compile_dir/log");

var_dump($files);

Outputs:

array(2) {
  [0]=>
  string(9) ".htaccess"
  [1]=>
  string(10) "index.html"
}

Specifying allowed file extensions:

$files = $this->Folder->getFiles("/compile_dir/log", array('html'));

var_dump($files);

Outputs:

array(1) {
  [0]=>
  string(10) "index.html"
}

Returning full file path:

$files = $this->Folder->getFiles("/compile_dir/log", array('html'), true);

var_dump($files);

Outputs:

array(1) {
  [0]=>
  string(60) "Z:\home\localhost\www\vesthelm\compile_dir\log\index.html"
}

Getting Directory Folders

In directory compile_dir there are 4 folders: cache, log, tmp and tpl to get folders:

$folders = $this->Folder->getFolders("/compile_dir");

var_dump($folders);

Outputs:

array(4) {
  [0]=>
  string(5) "cache"
  [1]=>
  string(3) "log"
  [2]=>
  string(3) "tmp"
  [3]=>
  string(3) "tpl"
}

Returning full folder path:

$folders = $this->Folder->getFolders("/compile_dir", true);

var_dump($folders);

Outputs:

array(4) {
  [0]=>
  string(51) "Z:\home\localhost\www\vesthelm\compile_dir\cache"
  [1]=>
  string(49) "Z:\home\localhost\www\vesthelm\compile_dir\log"
  [2]=>
  string(49) "Z:\home\localhost\www\vesthelm\compile_dir\tmp"
  [3]=>
  string(49) "Z:\home\localhost\www\vesthelm\compile_dir\tpl"
}