cp Function

public function cp(src, dest, ignoreErrors) result(res)

Copies a file or directory. Directories are copied recursively. Existing files are overwritten.

Syntax

 l = cp(src, dest, ignoreErrors)

Where:

  • src: Name of the file or folder to copy.
  • dest: Name of the destination
  • ignoreErrors: False to print a detailed description of the error message. Optional parameter. Default is False.

It returns True if the process has been succesful or False in case of error.

Example

The following program copies file1 to file2:

 PROGRAM cpExample
    USE FU_Files, ONLY: cp
    IMPLICIT NONE
    CHARACTER(LEN=:), ALLOCATABLE :: path1, path2
    path1='file1'
    path2='file2'
    IF (cp(path1, path2)) THEN
       WRITE(*,*) 'Success'
    ELSE
       WRITE(*,*) 'Error'
    END IF
 END PROGRAM cpExample

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: src

Name of the file to be copied.

character(len=*), intent(in) :: dest

Name of the destination file.

logical, intent(in), optional :: ignoreErrors

False to print a detailed description of the error message. Optional parameter. Default is False.

Return Value logical

True if the process has been succesful. False in case of error.


Contents