Copy a file from source to destination
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | source | |||
character(len=*), | intent(in) | :: | dest | |||
logical, | intent(out) | :: | success | |||
character(len=*), | intent(out), | optional | :: | error_msg |
subroutine sys_copy_file(source, dest, success, error_msg) character(len=*), intent(in) :: source, dest logical, intent(out) :: success character(len=*), intent(out), optional :: error_msg character(len=512) :: command integer :: exitstat if (get_os_type() == OS_WINDOWS) then ! Windows copy command - ensure proper path handling command = 'copy /Y "'//trim(escape_shell_arg(source))//'" "'//trim(escape_shell_arg(dest))//'" >nul 2>&1' else command = 'cp "'//trim(escape_shell_arg(source))//'" "'//trim(escape_shell_arg(dest))//'" 2>/dev/null' end if call execute_command_line(command, exitstat=exitstat) success = (exitstat == 0) if (present(error_msg)) then if (.not. success) then error_msg = "Failed to copy file" else error_msg = "" end if end if end subroutine sys_copy_file