Access file in a subfolder

Hi, is there any way to read a file in folder : data/data/myAppname/files?

Using 

local path = system.pathForFile( “files/audio.txt”, system.DocumentsDirectory )

it  will search in data/data/myAppname/app_data/files/

also i tried all other system.(…)Directory, but i cann’t access the one i need.Thanks for any idea

Question: I’m unclear where those files are… 

  • In your resource directory (same as your code).
    • If you have a fixed file that you need access to, put it in your resource structure.
  • In documents directory (the sandbox)?
    • If you want to read from here, you’ll have to write the file to this folder from the app.  Your sandbox does not get copied into the binary when you build.
    • The simulator has an option to open the sandbox folder if you can’t find your sandbox.

see io.readFile() extension in ssk here:

https://github.com/roaminggamer/SSKCorona/blob/master/com/roaminggamer/ssk/extensions/io.lua

function io.readFile( fileName, base ) local base = base or system.DocumentsDirectory local fileContents if( io.exists( fileName, base ) == false ) then return nil end local fileName = fileName if( base ) then fileName = system.pathForFile( fileName, base ) end -- fileName = io.repairPath( fileName ) local f=io.open(fileName,"r") if (f == nil) then return nil end fileContents = f:read( "\*a" ) io.close(f) return fileContents end

Then, 

-- For resource directory local data = io.readFile( "files/audio.txt", system.ResourceDirectory ) -- For documents directory local data = io.readFile( "files/audio.txt" )

No way, it gives me nil in:

if( io.exists( fileName, base ) == false ) then return nil end

Note: No need to quote my entire post back.  I know what I posted and it just makes the thread hard to read.

Yes.  Either require the entire module or also grab io.exists() from the code I posted a link to.

Or comment out the check for existence.  My modules are meant to be used as a whole and the link/paste was meant as a guide, not an entire solution.

Note: You’re best off just using my entire set of extensions.  They add features you’ll find yourself needing anyways.

https://github.com/roaminggamer/SSKCorona/tree/master/com/roaminggamer/ssk/extensions

io/string/table are the big ones.

To use them do the following:

  1. Download SSK

  2. Copy com/roaminggamer/ssk/ extensions into your game folder.

  3. Require…

    require “extensions.io” require “extensions.table” require “extensions.string”

DO NOT put these files in your root as you won’t be able to require them there.

Later you can graduate to the entire collection (SSK), but is probably a bit much for now.

Question: I’m unclear where those files are… 

  • In your resource directory (same as your code).
    • If you have a fixed file that you need access to, put it in your resource structure.
  • In documents directory (the sandbox)?
    • If you want to read from here, you’ll have to write the file to this folder from the app.  Your sandbox does not get copied into the binary when you build.
    • The simulator has an option to open the sandbox folder if you can’t find your sandbox.

see io.readFile() extension in ssk here:

https://github.com/roaminggamer/SSKCorona/blob/master/com/roaminggamer/ssk/extensions/io.lua

function io.readFile( fileName, base ) local base = base or system.DocumentsDirectory local fileContents if( io.exists( fileName, base ) == false ) then return nil end local fileName = fileName if( base ) then fileName = system.pathForFile( fileName, base ) end -- fileName = io.repairPath( fileName ) local f=io.open(fileName,"r") if (f == nil) then return nil end fileContents = f:read( "\*a" ) io.close(f) return fileContents end

Then, 

-- For resource directory local data = io.readFile( "files/audio.txt", system.ResourceDirectory ) -- For documents directory local data = io.readFile( "files/audio.txt" )

No way, it gives me nil in:

if( io.exists( fileName, base ) == false ) then return nil end

Note: No need to quote my entire post back.  I know what I posted and it just makes the thread hard to read.

Yes.  Either require the entire module or also grab io.exists() from the code I posted a link to.

Or comment out the check for existence.  My modules are meant to be used as a whole and the link/paste was meant as a guide, not an entire solution.

Note: You’re best off just using my entire set of extensions.  They add features you’ll find yourself needing anyways.

https://github.com/roaminggamer/SSKCorona/tree/master/com/roaminggamer/ssk/extensions

io/string/table are the big ones.

To use them do the following:

  1. Download SSK

  2. Copy com/roaminggamer/ssk/ extensions into your game folder.

  3. Require…

    require “extensions.io” require “extensions.table” require “extensions.string”

DO NOT put these files in your root as you won’t be able to require them there.

Later you can graduate to the entire collection (SSK), but is probably a bit much for now.