copy file()
This function copies file a to destination b. If b is a directory file, a will be copied to that directory without changing the filename. If b is a new filename, the file will be copied with the new name. If the destination directory does not already exist, an attempt is made to create it. If this is not possible, the function terminates with an error.
Parameter b is interpreted as a directory if it already exists or if the path name ends with a path separator. The slash "/" is expected as a path separator (also under Windows).
The function ends with an error if parameter a does not identify an existing file, and if copying to destination path b is not possible, e. g. because the destination directory could not be created or if the user did not have sufficient rights for that.
When the file is successfully copied, the full path of the copied file (destination file) is returned as the result of the function.
Parameters
Parameter |
Description |
a |
Source filename. |
b |
Destination filename/path. |
c |
(optional) "true" to delete source file afterwards. Default: "false". |
Examples
Parameter a |
Parameter b |
Parameter c |
Result |
Note |
./temp/myFile.jpg |
./temp/out |
|
./temp/out/myFile.jpg |
Destination b is only interpreted as a directory if it is an existing directory, otherwise as a file name. |
./temp/myFile.jpg |
./temp/out/ |
|
./temp/out/myFile.jpg |
Destination b is interpreted as a directory if it has a "/" at the end, even if it does not yet exist. In that case, an attempt is made to create it. |
./temp/myFile.jpg |
./temp/out/CopyOfMyFile.jpg |
|
./temp/out/CopyOfMyFile.jpg |
If the destination directory ./temp/out/ does not already exist, an attempt is made to create it. |