copyFile()

Copies the specified source file to the specified target file or to the specified directory.

Synopsis

bool copyFile(string source, string target [, bool par3]);

Parameters

Parameter Meaning
source Source directory. You can specify an absolute path or a relative path from the PROJ_PATH directory. NOTE: An empty string "" is interpreted as PROJ_DIR. If an empty string "" is used as source, the whole project is copied to the given path.
target Target directory. You can specify an absolute path or a relative path from the PROJ_PATH directory. NOTE: an empty string "" is interpreted as PROJ_DIR.
par3

(Preserve bit), optional parameter. If the parameter is not available the default value is used. The default = false.

0 means that the File date = current time. If the value is 1 (TRUE) the target file gets the same time as the source file.

Authorizations are either granted with user +rw or go+r

(Read and write rights for the user, read rights for a group and others)

1 time and authorization are imported (getFileTimes() setFileTimes() )

Return Value

If copying unsuccessful 0, copying OK 1.

Errors

-

Description

The file specified in source is copied to the file specified in target, the source and target directory must also be specified. Nonexistent subdirectories are automatically created.

Wichtig: If a file with the same name as the target file already exists in the target directory, it is overwritten. So if you copy the file "test.txt"; from "c://test1//test.txt"; to c://test2//test.txt"; and a file called "test.txt"; already exists in the test2 directory, the test.txt file is overwritten.
Wichtig: If a file name contains special characters (e.g. Chinese characters), the language of the operating system must be changed (in this case to Chinese).
Anmerkung: In case the copied file is a symbolic link (symlink), the referenced file is copied, not the link itself. In this case, no file metadata is copied except for the permissions.
Anmerkung: A file that should be copied into a target directory can also be copied directly to the target directory without specifying a file name. Thereby, the copied file is named as the source file.
main()
{
  bool ok = 0;

  // The file in c:/test1/test.txt is
  // copied to c:/test2/test.txt.
  ok = copyFile ("c://test1//test.txt","c://test2//test.txt");

      if(!ok)
      {
        //...Error handling...;
    DebugN("File was not copied", ok);
  }
  else
  {
    DebugN("File was not copied", ok);
  }
}

Assignment

File functions

Availability

CTRL

See also