Type Constant Library system.* Revision Current Public Release (2013.2100) Keywords system directory See also system.pathForFile()
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."
You should not 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
"baseDirectory" as a parameter (e.g.,
media.playSound(), etc.). 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. Unlike the
/tmp directories, the resource directory is not viewable via File → Show Project Sandbox.
To restate what was mentioned above:
system.ResourceDirectory is where your
main.lua file and generally all of your asset (resource) files are stored. For security reasons, this directory is read-only and enforced by the operating system, not by Corona.
File access in Corona is based on the underlining operating system which varies by platform. On iOS devices, you can access files in all of the directories described above. On Android, however, there is no literal
system.ResourceDirectory because all resource files reside inside a compressed APK file.
Corona allows direct loading of images and audio files using the appropriate APIs, but it has limited access to resource files on Android using the file I/O APIs. Specifically, the following types can not be read from the resources directory:
Because of this limitation, if you have files of these types bundled in the core directory that you need to copy to another directory, you must change the file name so it can be accessed by the file I/O APIs. For example, if you want to move
cat.png from the resource directory to the documents directory, it must be renamed
cat.png.txt to be copied. See Working With Subfolders in the Reading and Writing Files guide for details.
This example will read a
data.txt file located in the assets directory (the same directory containing
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