copyFilteredFiles.php
Table of Contents
Functions
- copyFilteredFiles() : bool
- Recursively copies files and directories from a source to a destination with filtering.
Functions
copyFilteredFiles()
Recursively copies files and directories from a source to a destination with filtering.
copyFilteredFiles(string $sourceDir, string $destDir[, array<string|int, string> $excludePatterns = [] ][, callable|null $filterCallback = null ][, bool $followLinks = false ]) : bool
This function iterates through a source directory and copies its contents to a destination directory, preserving the folder structure. It provides two methods for filtering which files and directories get copied:
$excludePatterns: An array of glob/regex patterns. Any file or directory matching a pattern in this array will be skipped. SeeshouldExcludeFile().$filterCallback: An optional user-defined function. This callback receives the full path of each item and must returntruefor the item to be copied.
Destination directories are created as needed.
Symbolic links. By default a link is reproduced as a link, with the target it was written
with: a relative link stays relative, an absolute one stays absolute, and the target is never
read, so nothing is copied through a link. Pass $followLinks to read them instead — a linked
directory is then walked and a linked file copied, as if the link were the thing it points at.
A link pointing at nothing is skipped either way. Both the exclude patterns and the filter
callback see the link's own path, not its target's.
Parameters
- $sourceDir : string
-
The path to the source directory to copy from.
- $destDir : string
-
The path to the destination directory.
- $excludePatterns : array<string|int, string> = []
-
An array of patterns to exclude from the copy.
- $filterCallback : callable|null = null
-
Optional callback for custom filtering. It receives the file path and should return
trueto include it. - $followLinks : bool = false
-
Whether to read symbolic links instead of reproducing them (Default false).
Tags
Return values
bool —Returns true if at least one file or directory was copied, false otherwise.