# copyFile problem

**URL:** <https://forums.solar2d.com/t/copyfile-problem/351831>\
**Category:** Games\
**Created:** [July 10, 2020, 4:34pm UTC](https://forums.solar2d.com/t/copyfile-problem/351831 "2020-07-10T16:34:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kapcioks](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/k/8491ac/32.png) [@kapcioks](https://forums.solar2d.com/u/kapcioks)\
**Post date:** [July 10, 2020, 4:34pm UTC](https://forums.solar2d.com/t/copyfile-problem/351831/1 "2020-07-10T16:34:47Z")

</div>

Hello. I have problem with this copyFile function.  
I want to copy file “nophoto.jpg” from resources to documents as “copy.jpg”.  
On Corona Simulator on PC it works but on my phone it doesn’t work fine. It copies black screen with 0B, blank jpg.

> **copyFile**
>
> ```
> local function copyFile(dstName)
> local results = false
>  
> local rfilePath = system.pathForFile( "nophoto.jpg" )
> local wfilePath = system.pathForFile( dstName, system.DocumentsDirectory )
>  
> local rfh = io.open( rfilePath, "rb" )
> local wfh = io.open( wfilePath, "wb" )
>  
> if not wfh then
> print( "writeFileName open error!" )
> return false -- error
> else
> -- Read the file from the Resource directory and write it to the destination directory
> local data = rfh:read( "*a" )
> if not data then
> print( "read error!" )
> return false -- error
> else
> if not wfh:write( data ) then
> print( "write error!" )
> return false -- error
> end
> end
> end
>  
> results = 2 -- file copied
>  
> -- Clean up our file handles
> rfh:close()
> wfh:close()
>  
> return results
> end
> 
> ```

I use it this way: `copyFile("copy.jpg")`

Any thoughts?

---

<div class="post-metadata">

**Author:** ![XeduR](https://forums.solar2d.com/user_avatar/forums.solar2d.com/xedur/32/256_2.png) [@XeduR](https://forums.solar2d.com/u/XeduR)\
**Post date:** [July 10, 2020, 4:47pm UTC](https://forums.solar2d.com/t/copyfile-problem/351831/2 "2020-07-10T16:47:32Z")

</div>

[https://docs.coronalabs.com/api/library/system/ResourceDirectory.html#android](https://docs.coronalabs.com/api/library/system/ResourceDirectory.html#android)

---

<div class="post-metadata">

**Author:** ![roaminggamer](https://forums.solar2d.com/user_avatar/forums.solar2d.com/roaminggamer/32/134_2.png) [@roaminggamer](https://forums.solar2d.com/u/roaminggamer)\
**Post date:** [July 10, 2020, 5:26pm UTC](https://forums.solar2d.com/t/copyfile-problem/351831/3 "2020-07-10T17:26:50Z")

</div>

> **[Super Starter Kit 2](https://roaminggamer.github.io/RGDocs/pages/SSK2/)**
>
> Roaming Gamer, LLC. SSK 2 Documentation

> > [Files Library - Super Starter Kit 2](https://roaminggamer.github.io/RGDocs/pages/SSK2/libraries/files/)

With ssk, you’d do that like this:

```auto
local src = ssk.files.resource.getPath("copy.jpg") -- File from root folder of project
local dst = ssk.files.documents.getRoot() -- Path to documents folder on current system
ssk.files.cpFile( src, dst )

```

---

<div class="post-metadata">

**Author:** ![StarCrunch](https://forums.solar2d.com/user_avatar/forums.solar2d.com/starcrunch/32/67_2.png) [@StarCrunch](https://forums.solar2d.com/u/StarCrunch)\
**Post date:** [July 10, 2020, 5:27pm UTC](https://forums.solar2d.com/t/copyfile-problem/351831/4 "2020-07-10T17:27:11Z")

</div>

If this is Android, I wrote [this plugin](http://ggcrunchy.github.io/corona-plugin-docs/DOCS/AssetReader/api.html) to address this very thing. The `Read` function is basically an `open(filename)` + `read("*a")` call.

---

<div class="post-metadata">

**Author:** ![TGS](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/t/f19dbf/32.png) [@TGS](https://forums.solar2d.com/u/TGS)\
**Post date:** [October 26, 2023, 4:59am UTC](https://forums.solar2d.com/t/copyfile-problem/351831/5 "2023-10-26T04:59:52Z")

</div>

i tried to copy a image to my : …"/Android/data/com.solar2d.app.Donzda/" and dosent work, how to manage files in my folder? @roaminggamer

---

<div class="post-metadata">

**Author:** ![TGS](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/t/f19dbf/32.png) [@TGS](https://forums.solar2d.com/u/TGS)\
**Post date:** [October 26, 2023, 7:44am UTC](https://forums.solar2d.com/t/copyfile-problem/351831/6 "2023-10-26T07:44:49Z")

</div>

how to get status, onCompletee. I want to show some message ou spin or progressbar while coping my files
