Skip to content

Instantly share code, notes, and snippets.

@benbahrenburg
Created December 23, 2011 21:04
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save benbahrenburg/1515352 to your computer and use it in GitHub Desktop.
Save benbahrenburg/1515352 to your computer and use it in GitHub Desktop.
Titanium : How to find the Private Directory
function privateDocumentsDirectory(){
Ti.API.info('We need to open a file object to get our directory info');
var testFile = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory);
Ti.API.info('Now we remove the Documents folder reference');
var privateDir = testFile.nativePath.replace('Documents/','');
Ti.API.info('This is our base App Directory =' + privateDir);
Ti.API.info('Now we add the Private Documents Directory');
privateDir+='Library/Private%20Documents/';
Ti.API.info('Our new path is ' + privateDir);
return privateDir;
};
var myDbName = 'foo123';
Ti.API.info('We create a db to test our method')
var testDb = Ti.Database.open(myDbName);
var testNativePath = testDb.getFile().nativePath;
Ti.API.info('Our nativePath to test against is ' + testNativePath + ' this is what we need to end up with');
var privateDocFolder = privateDocumentsDirectory();
Ti.API.info('Our Private Document Folde is ' + privateDocFolder);
Ti.API.info("Let's see if we can find our database");
var dbCheck = Ti.Filesystem.getFile(privateDocFolder, myDbName+ '.sql');
Ti.API.info('Did we find it? ' + dbCheck.exists());
Ti.API.info('Do our file paths match? ' + (dbCheck.nativePath==testNativePath));
Ti.API.info('Example Finished');
@benbahrenburg
Copy link
Author

This an example on how to find the Private Documents directory in Appcelerator Titanium. In iOS 5 and Titanium SDK 1.8+ your database will now be stored in this directory.

@shouse
Copy link

shouse commented May 1, 2018

Wondering if this is still valid. Guess I need to find that out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment