I need to use [file\_copy](https://api.drupal.org/api/drupal/core%21modules%21file%21file.module/function/file_copy/8.6.x) in a custom module in D8.

The function `file_copy` requires the first parameter to be a `File Entity`. Here is what I have tried but it doesn't work and returns an error:

**TypeError: Argument 1 passed to file\_copy() must be an instance of Drupal\file\FileInterface, instance of stdClass given**.

```
$file_path = drupal_realpath("public://Testttt58.png");
$file = (object) array(
            'uid' => 1,
            'uri' => $file_path,
            'filemime' => mime_content_type($file_path),
            'display' => 1,
            'filename' => "Testttt58.png"
);
$fileUpload = file_copy($file, "public://TestFolder", FILE_EXISTS_RENAME);

```

Here is the output of `kint($file);`

[![enter image description here](https://i.stack.imgur.com/w3thx.png)](https://i.stack.imgur.com/w3thx.png)

How can I solve this?