Files
Provides methods to manage server side files.
Upload / Download
File transfers are performed using the client-side Files module.
Using S3
If you'd like to transfer files using Amazon S3 take a look at the S3 Lite plugin for Corona.
list
List the files in the specified directory path. Returns a table array, or nil and an error.
core.files.list(dirpath)
Parameters
Name | Description | Type | Required |
---|---|---|---|
dirpath | The directory to list. | String | Y |
local list, err = core.files.list("imgs")
This method will only list the files in the directory, not any directories. If no files are present, it will return an empty table.
move
Move a file in the server files directory.
core.files.move(srcpath, destpath, overwrite)
Parameters
Name | Description | Type | Required |
---|---|---|---|
srcpath | The source filepath with extension. | String | Y |
destpath | The destination filepath with extension. | String | Y |
overwrite | If true overwrite existing files (default false). | Boolean | N |
Example
local ok, err = core.files.move("imgs/image01.png", "assets/image01.png")
copy
Copy a file in the server files directory.
core.files.copy(srcpath, destpath, overwrite)
Parameters
Name | Description | Type | Required |
---|---|---|---|
srcpath | The source filepath with extension. | String | Y |
destpath | The destination filepath with extension. | String | Y |
overwrite | If true overwrite existing files (default false). | Boolean | N |
Example
local ok, err = core.files.copy("imgs/image01.png", "assets/image01.png")
remove
Remove a file from the server files directory. Returns true on success, or nil and an error.
core.files.remove(filepath)
Parameters
Name | Description | Type | Required |
---|---|---|---|
filepath | The source filepath. | String | Y |
Example
local ok, err = core.files.remove("imgs/image002.png")
rename
Rename a file in the server files directory. Returns true on success, or nil and an error.
core.files.rename(filepath, new_name)
Parameters
Name | Description | Type | Required |
---|---|---|---|
filepath | The source filepath. | String | Y |
new_name | The name to rename the file to. | String | Y |
Example
local ok, err = core.files.rename("imgs/image001.png", "image002.png")
Note
This rename method will not move a file. Any path supplied to the new_name parameter will be ignored.