How to access a folder inside DocumentsDirectory

Hello,

I’ve created a folder inside the system.DocumentsDirectory using the Lua File System example:

local lfs = require "lfs"  
  
local temp\_path = system.pathForFile( "", system.DocumentsDirectory )  
  
local success = lfs.chdir( temp\_path )  
local new\_folder\_path  
  
if success then  
 lfs.mkdir( "MyNewFolder" )  
 new\_folder\_path = lfs.currentdir() .. "/MyNewFolder"  
end  

now I want to save an image inside MyNewFolder. i’ve tried system.DocumentsDirectory/MyNewFolder and new_folder_path, but it doesn’t work.

What path should i give to access this newly created folder?

Thanks [import]uid: 175611 topic_id: 33950 reply_id: 333950[/import]

Hello Ali,
Did you try something like this?

local filePath = system.pathForFile( "/myFolder/", system.DocumentsDirectory )  
print(filePath)  

I’m getting the proper path to that specific folder in my testing… but maybe this isn’t exactly what you need to accomplish? Let me know if you make any progress and I can tinker with it more. :slight_smile:

Brent
[import]uid: 200026 topic_id: 33950 reply_id: 134987[/import]

Thank you Brent,

the path of the new folder is being displayed on terminal. But when i try to save the image in this new folder, i fail. The images are still being saved in the DocumentsDirectory.

I tried this:

 local filePath = system.pathForFile( "/MyNewFolder/", system.DocumentsDirectory )  
 print(filePath)  
  
 display.save(display.getCurrentStage(), "image"..index..".jpg", filePath)  

how can i access the MyNewFolder to read and write into it? [import]uid: 175611 topic_id: 33950 reply_id: 135081[/import]

Hi Ali,
I have another test code for you (below). This one specifies the subdirectory as part of the “filename” parameter. You can’t use system.pathForFile() for subdirectories, except in File I/O calls. If the API calls for a baseDirectory parameter (as display.save() does), it needs to be one of the system.xyz directory constants.

display.save( displayObject, "/MyNewFolder/"..filename, system.DocumentsDirectory )  

Let me know if you have any luck with this,
Thank you,
Brent
[import]uid: 200026 topic_id: 33950 reply_id: 135179[/import]

Hello Ali,
Did you try something like this?

local filePath = system.pathForFile( "/myFolder/", system.DocumentsDirectory )  
print(filePath)  

I’m getting the proper path to that specific folder in my testing… but maybe this isn’t exactly what you need to accomplish? Let me know if you make any progress and I can tinker with it more. :slight_smile:

Brent
[import]uid: 200026 topic_id: 33950 reply_id: 134987[/import]

Thank you Brent,

the path of the new folder is being displayed on terminal. But when i try to save the image in this new folder, i fail. The images are still being saved in the DocumentsDirectory.

I tried this:

 local filePath = system.pathForFile( "/MyNewFolder/", system.DocumentsDirectory )  
 print(filePath)  
  
 display.save(display.getCurrentStage(), "image"..index..".jpg", filePath)  

how can i access the MyNewFolder to read and write into it? [import]uid: 175611 topic_id: 33950 reply_id: 135081[/import]

Hi Ali,
I have another test code for you (below). This one specifies the subdirectory as part of the “filename” parameter. You can’t use system.pathForFile() for subdirectories, except in File I/O calls. If the API calls for a baseDirectory parameter (as display.save() does), it needs to be one of the system.xyz directory constants.

display.save( displayObject, "/MyNewFolder/"..filename, system.DocumentsDirectory )  

Let me know if you have any luck with this,
Thank you,
Brent
[import]uid: 200026 topic_id: 33950 reply_id: 135179[/import]

That works!

Thanks a million Brent! [import]uid: 175611 topic_id: 33950 reply_id: 136560[/import]

That works!

Thanks a million Brent! [import]uid: 175611 topic_id: 33950 reply_id: 136560[/import]