Skip to content

Instantly share code, notes, and snippets.

@jeffatstepup
Forked from benbahrenburg/gist:1515352
Created September 28, 2012 10:15
Show Gist options
  • Select an option

  • Save jeffatstepup/3799012 to your computer and use it in GitHub Desktop.

Select an option

Save jeffatstepup/3799012 to your computer and use it in GitHub Desktop.

Revisions

  1. @benbahrenburg benbahrenburg created this gist Dec 23, 2011.
    25 changes: 25 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    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');