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
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.
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.
Tags
Return values
bool —Returns true if at least one file or directory was copied, false otherwise.