# copy

## Description

Copies an existing file in the cache directory of the mobile phone.

## Input / Parameter

| Name                | Description                                                                                             | Input Type | Default | Options | Required |
| ------------------- | ------------------------------------------------------------------------------------------------------- | ---------- | ------- | ------- | -------- |
| sourceFileName      | The name of the source file to copy.                                                                    | Text       | -       | -       | Yes      |
| sourceFolder        | The folder path of the source file. If this input is provided, it will be appended to the storage path. | Text       | -       | -       | No       |
| destinationFileName | The name of copied file.                                                                                | Text       | -       | -       | Yes      |
| destinationFolder   | The folder path of the copied file. If this input is provided, it will be appended to the storage path. | Text       | -       | -       | No       |
| extra               | The stored value that is passed to all the callbacks.                                                   | Any        | -       | -       | No       |

## Output

| Description                        | Output Type |
| ---------------------------------- | ----------- |
| Returns the formatted information. | Object      |

### Object

| Key     | Description                                                             | Output Type |
| ------- | ----------------------------------------------------------------------- | ----------- |
| success | Boolean value to denote whether the function was executed successfully. | Text        |
| message | The message to print.                                                   | Text        |
| data    | Any additional message or data to print.                                | Text        |

## Callback

### callback

The action performed if this function runs successfully.

| Description                                           | Output Type |
| ----------------------------------------------------- | ----------- |
| Returns an object that contains the file information. | Object      |

### errorCallback

The action performed if this function does not run successfully.

| Description               | Output Type |
| ------------------------- | ----------- |
| Returns an error message. | Text        |

## Example

In this example, we will copy a file and view the contents in the console.

```js
Note: This example will only work after the user has created a file using `File.write` function.
```

### Steps

1. Drag a button component to a page in the mobile designer.

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-e90d70795ebe97ce780781e4b1fcb7e64eba4367%2Fcopy-step-1.png?alt=media)
2. Select the event `press` and drag the `File.copy` function to the event flow. Fill in the parameters of the function.

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-9c1f79963ea12abd16b1cf6ae79ebce2b10c121a%2Fcopy-step-2.png?alt=media)

### Result

1. Open the installed app on a device with a debugger on and try to press the button.
2. If the copied file exists, user should be able to see the content on the console.

   ![](https://399701567-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FwmJ1RKjM2uNFaL6fO3Xu%2Fuploads%2Fgit-blob-14cfdf48ad08d9537681929c358be41eb3951694%2Fcopy-result-1.png?alt=media)
