I'm trying to access my application's data directory via what I think is the standard way to do it:
Ti.Filesystem.applicationDataDirectoryHowever, when I do that, I get the following error like it doesn't exist:
"Result of expression 'Ti.Filesystem' [undefined] is not an object.";Any ideas of how to get this to work?
Whenever you get an undefined object error and the spelling is correct (as in this case), the most likely explanation is this is the first time you have referenced the given class (Filesystem in this case). Due to the incremental nature of how Titanium builds projects, it requires a full build to incorporate new classes the first time they are used.
Try forcing a full rebuild and see what happens. In Ti Studio, use menu Project > Clean, then try again.
Try looking at these resources:
Basically if you create a reference object to the data directory first, so if you wanted to read a file form within that directory:
var dataDirectory = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory);
then you could get all the contents of the directory using this:
var ddfiles = dataDirectory.getDirectoryListing();
of course you would need to loop through each entry as you would be returned an array.
ddfiles would be the first file in the directory.
Reference the Filesystem API docs as well:
Think you can help? Login to answer this question!