system.ApplicationSupportDirectory

Type Constant
Library system.*
Revision Release 2024.3703
Keywords system directory, ApplicationSupportDirectory
See also system.pathForFile()
system.CachesDirectory
system.DocumentsDirectory
system.ResourceDirectory
system.TemporaryDirectory

Overview

Used with system.pathForFile() to create a path for storing and retrieving files that need to persist between application sessions but are not visible to users. For example, this might be used for storing downloadable levels for a game.

This property can also be used with other APIs requesting baseDir as a parameter, for example display.newImageRect(), display.save(), etc.

Notes
  • In the Corona Simulator, this will be in a sandboxed folder on a per-application basis. You can view its directories/files via FileShow Project Sandbox.

  • On iOS, this information is backed up by syncing.

Syntax

system.ApplicationSupportDirectory

Example

-- Get path for file "data.txt" in the application support directory
local path = system.pathForFile( "data.txt", system.ApplicationSupportDirectory )

-- Open the file from the path
local fh, reason = io.open( path, "r" )

if fh then
    -- File exists; read its contents into a string
    local contents = fh:read( "*a" )
    print( "Contents of " .. path .. "\n" .. contents )
    
else
    -- File open failed; output the reason
    print( "File open failed: " .. reason )

    -- Create file since it doesn't exist yet
    fh = io.open( path, "w" )

    if fh then
        print( "Created file" )
    else
        print( "Create file failed!" )
    end

    local numbers = { 1,2,3,4,5,6,7,8,9 }
    fh:write( "Feed me data!\n", numbers[1], numbers[2], "\n" )

    for _,v in ipairs( numbers ) do 
        fh:write( v, " " )
    end

    fh:write( "\nNo more data\n" )
end
 
io.close( fh )