Thanks, Tom! You saved my day
Since the file name is required, can’t you use the name of a known file (at least in the case of system.ResourceDirectory) and strip the filename off from the results? Main.lua won’t be there since it’s part of the compiled code, but you could leave a small data file, perhaps Icon.png or something to use to get a complete path to a file.
Rob
Another Corona engineer, Michael I believe, replied to a question in the Windows desktop beta forum and advised a user to get the path to the documents directory by passing nil as the first argument to pathForFile…
So there seems to be a differing opinion here? Even if it is unsupported, it would be nice to know why the behaviour changed on Mac only recently?
Edit: Link to Michael’s post: https://forums.coronalabs.com/topic/58409-systemdirectory-game-files/#entry302180
The documentation says either explicitly pass a file name or pass “nil” as the first parameter. Don’t pass an empty string. Don’t pass just a slash “/”.
If this behavior does not work on a platform, then we will need a bug report.
Thanks
Rob
Got it, I’ll try that and see how it goes. I’ll open a bug report if needed.
Thanks Rob.
Hi,
I’m use this code for write time data, but i’m do not find “time.txt” on phone,where save this file(“time.txt”) ?
If this code do not worke fore saving file(data), What functions can I use?
local path = system.pathForFile( “time.d.txt”, system.DocumentsDirectory )
local function updateTime()
local time = os.date("*t")
local saveData = time.hour
local file = io.open( path, “a+” )
file:write( saveData )
io.close( file )
local saveData = “:”
local file = io.open( path, “a+” )
file:write( saveData )
io.close( file )
local saveData = time.min
local file = io.open( path, “a+” )
file:write( saveData )
io.close( file )
local saveData = “:”
local file = io.open( path, “a+” )
file:write( saveData )
io.close( file )
local saveData = time.sec
local file = io.open( path, “a+” )
file:write( saveData )
io.close( file )
end
local clockTimer = timer.performWithDelay( 1000, updateTime, -1 )
Help me please
Engineering has given this a thorough test and it works as we have it documented. Let me clarify that part.
system.pathForFile() takes two parameters: The file and the sandbox directory you want to use. If you just want the path to the sandbox, pass in nil, such as:
local path = system.pathForFile( nil, system.DocumentsDirectory )
Using “” or “/” or other combinations for the file may work on some platforms, but it’s not how we expect it to work. There is one exception to this and it’s getting the path to system.ResourceDirectory on Android. Because there isn’t one (it’s just a zip file), calling:
local path = system.pathForFile( nil, system.ResourceDirectory )
on Android will return a nil since there is no such thing. If you leave off the second parameter, it defaults to system.ResourceDirectory.
Hope this helps!
Rob