-
-
Save tzmartin/2716580 to your computer and use it in GitHub Desktop.
Titanium : How to find the Private Directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment