Kotchasan

File
in package

Class for managing files and directories.

Tags
see
https://www.kotchasan.com/

Table of Contents

copyDirectory()  : mixed
Copy a directory recursively.
ext()  : string
Get the file extension of a file (e.g., 'config.php' returns 'php').
listFiles()  : mixed
Get the list of files in a directory and its subdirectories.
makeDirectory()  : bool
Create and validate a directory for writing.
removeDirectory()  : mixed
Recursively delete a directory and its files, or only the files inside the directory.

Methods

copyDirectory()

Copy a directory recursively.

public static copyDirectory(string $sourceDir, string $destDir) : mixed
Parameters
$sourceDir : string

Source directory path (with trailing slash)

$destDir : string

Destination directory path (with trailing slash)

Return values
mixed

ext()

Get the file extension of a file (e.g., 'config.php' returns 'php').

public static ext(string $path) : string
Parameters
$path : string

File path

Return values
string

File extension (lowercase)

listFiles()

Get the list of files in a directory and its subdirectories.

public static listFiles(string $dir, array<string|int, mixed> &$result[, array<string|int, mixed> $filter = [] ]) : mixed
Parameters
$dir : string

Directory path (with trailing slash)

$result : array<string|int, mixed>

Array to store the found files

$filter : array<string|int, mixed> = []

(optional) File extensions to filter (lowercase). An empty array means all extensions.

Return values
mixed

makeDirectory()

Create and validate a directory for writing.

public static makeDirectory(string $dir[, int $mode = 0755 ]) : bool
Parameters
$dir : string

Directory path

$mode : int = 0755

(optional) Directory permission mode (default: 0755)

Return values
bool

True if the directory exists or is created successfully and is writable, false otherwise

removeDirectory()

Recursively delete a directory and its files, or only the files inside the directory.

public static removeDirectory(string $dir[, bool $removeSelf = true ]) : mixed
Parameters
$dir : string

Directory path to delete (with trailing slash)

$removeSelf : bool = true

True (default) to delete the directory itself, false to delete only the files inside

Return values
mixed

Search results