×
A new build of Corona SDK is now available to subscribers. Not a subscriber? Subscribe now.
CoronaSDK 2012.821 | Released: 23 May 2012, 2:01am | What's New | Download Now

system.ResourceDirectory

Description:

Used with system.pathForFile to create a path for retrieving files where all the application assets exist (e.g., image and sound files). This often called the "app bundle."

Note: You should never create, modify, or add files to this directory. Doing so will prevent the device from verifying the integrity of your application; in some cases the device will treat your application as malware and refuse to launch your application.

This property can also be used with other APIs requesting a "baseDirectory" as a parameter (e.g., display.newImage, display.save, media.playSound). The Resource directory is generally the default directory if no directory is specified.

In the Corona Simulator this will be in a sandboxed folder on a per-application basis.

Note: Unlike the /Documents and /tmp directories, the Resource directory is not viewable using "Show Project Sandbox" in the simulator.

Syntax:

path = system.pathForFile( filename, system.ResourceDirectory )

Example:

This example will read a "data.txt" file located in the assets directory (the same directory that has "main.lua").

local path = system.pathForFile( "data.txt", system.ResourceDirectory )
 
local file = io.open( path, "r" )
 
if file then -- nil if no file found
        local contents = file:read( "*a" )
        print( "Contents of " .. path .. "\n" .. contents )
        io.close( file )
end

Parameters:

None.

Returns:

userdata
Returns a special userdata constant pointing to the App Bundle (assets) directory. (This is not a string.)

Remarks:

To restate what was mentioned above: The system.ResourceDirectory is where your main.lua file and generally all your asset (resource) files are stored. For security reasons, this directory is made read-only and enforced by the operating system and not Corona. If you need to update something in the resource directory, you need to move it to the Documents or Temporary directories first.

Supported on operating systems and platforms for build numbers shown:
  • Mac OS X:
    Corona SDK 1.0
  • Windows:
    Corona SDK 2.0
  • iOS:
    Corona SDK 1.0
  • Android:
    Corona SDK 2.0

Replies

coderebelbase's picture
coderebelbase
User offline. Last seen 3 weeks 2 days ago. Offline
Joined: 1 Feb 2010

oops, wrong url

bpappin's picture
bpappin
User offline. Last seen 6 days 23 hours ago. Offline
Joined: 19 Jan 2011

Which directory is this for Android apps?

shinhan.wu
User offline. Last seen 5 weeks 1 hour ago. Offline
Joined: 6 Oct 2011

the example seems not work for Android apps