The OpenD Programming Language

copy

Copy file from to file to. File timestamps are preserved. File attributes are preserved, if preserve equals Yes.preserveAttributes. On Windows only Yes.preserveAttributes (the default on Windows) is supported. If the target file exists, it is overwritten.

  1. void copy(RF from, RT to, PreserveAttributes preserve)
  2. void copy(RF from, RT to, PreserveAttributes preserve)

Parameters

from RF

string or range of characters representing the existing file name

to RT

string or range of characters representing the target file name

preserve PreserveAttributes

whether to preserve the file attributes

Throws

FileException on error.

Examples

auto source = deleteme ~ "source";
auto target = deleteme ~ "target";
auto targetNonExistent = deleteme ~ "target2";

scope(exit) source.remove, target.remove, targetNonExistent.remove;

source.write("source");
target.write("target");

assert(target.readText == "target");

source.copy(target);
assert(target.readText == "source");

source.copy(targetNonExistent);
assert(targetNonExistent.readText == "source");

Meta