Documentation

CopyDirFiles

bool
CopyDirFiles(
 string path_from,
 string path_to,
 bool rewrite = true,
 bool recursive = false,
 bool DeleteAfterCopy = false,
 string exclude = ""
);

The function copies files and directories. Returns true on success, or false otherwise. .

Function parameters

ParameterDescription
path_from Absolute path to a directory or file which is to be copied.
path_to Absolute path to the destination directory. The path specified in this parameter will be checked by the CheckDirPath function.
rewrite Determines whether to overwrite the existing files.
Optional parameter. True by default which means to overwrite.
recursive Specifies to recursively copy all subdirectories and files of the path specified in the from parameter.
Optional parameter. False by default which means not to use recursion.
delete_after_copy Specified to delete the path passed in the from parameter after the copying process is complete (which in fact means moving directories and files).
Optional parameter, False by default (do not to delete).
exclude If this parameter is specified, files and folders which names start with the value of this parameter - will not be copied.

See Also

Examples of use

<?
// copy files from the folder /temp1/ to /temp2/
CopyDirFiles($_SERVER["DOCUMENT_ROOT"]."/temp1", $_SERVER["DOCUMENT_ROOT"]."/temp2");
?>

If one file is copied, not only the source must be specified, but also the destination. Name of destination file can be different from the name of the source file.

CopyDirFiles($_SERVER["DOCUMENT_ROOT"]."/temp1/file.ex", $_SERVER["DOCUMENT_ROOT"]."/temp2/file.ex");


© «Bitrix24», 2001-2024