File

Staric helper class to handle files and directories

Read, copy, delete etc. helper functions.

Example

Read file content

$content = File::read($myFileName);

Traverse

Read all directories and files:

foreach ( File::getDirs($directory) as $subdir ){
    $txt = "Directory: '.$subdir['name'].' path is '.$subdir['dir'];
}
foreach ( File::getFiles($directory) as $file ){
    $txt = "File: '.$file['name'].' of type '.$file['type'].' path is '.$file['file'];
}

Read and write

Read file content

 $content = File::read($file);

Set content to file

 File::write($file, $content);

Add content to file

 File::add($file, $content);

Delete and copy

Delete file or directory

 File::delete($file);
 File::delete($directory); // Delete all files and subdirectories

Copy file

 File::copy($file, newFile);

File methods

Method Return Description
File::isFile($filename) bool Return true, if file exists.
File::getType($filename) string Get filename extension part, lowercase.
File::getPath($filename) string Get path of filename. (drop last part).
File::read($filename) string Read file content.
File::write($filename, $string) bool Write content to file.
File::add($filename, $string) bool Add content to file.
File::delete($filename) bool Delete file.
File::rename($filename) bool Rename file.
File::copy($oldName, $oldName) bool Copy file to new file

Directory methods

Method Return Description
File::isDir($dirname) bool Return true, if directory exists.
File::createDir($dirname) bool Create directory
File::delete($dirname) bool Delete directory and all subdirectoreis / files.
File::rename($dirname, $createFullPath=false) bool Create directory
File::isEmptyDirectory($directory) bool Check if directory is empty
File::getDirs($directory) array Get list of directories in directory
File::isDirs($directory) bool Check if directory has directories
File::getFiles($directory[,$filetypes='']) array Get list of files in directory
File::isFiles($directory[,$filetypes='']) bool Check if directory has files.