Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Filesystem - how to create & delete file folder for caching

With no further reference on filesystem object, and documents on how to use them. I see there's more on filesystem methods mentioned on desktop api but it's blank on mobile version such as createDirectory…etc here https://developer.appcelerator.com/apidoc/desktop/1.0/Titanium.Filesystem-module

I'm not sure it's available on iPhone/iPad or not, if it does, would anyone direct me how to create a directory under Titanium.Filesystem.applicationDataDirectory ?

The idea is to cache files and images under a dynamically create folder on XHR load, then on next app open, access that cached data if no network detected, and delete the entire folder on next new successful load. I would just use the file.nativePath but doing so will require me to delete the files one by one, which means i have to create a reference for a list of old files name.

Thanks

— asked May 5th 2010 by Daniel Lim
  • cache
  • filesystem
  • ipad
  • iphone
0 Comments

4 Answers

  • This works for me:

    parent = Ti.Filesystem.getresourcesDirectory();
    var new_folder = Titanium.Filesystem.getFile(parent, 'new_folder_name');
    if( !new_folder.exists() )
    {
      new_folder.createDirectory();
    }
    
    — answered September 14th 2010 by Kelly Redd
    permalink
    0 Comments
  • You're missing the ().

    It's: Titanium.Filesystem.getApplicationDataDirectory()

    — answered May 5th 2010 by Mark Burggraf
    permalink
    0 Comments
  • Hi Mark,

    Thanks for the help, both getting the same result, showing app data directory. But that's not the question, you know how to create a directory from the file object? Thanks

    var currentdir = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'somefilename');
    
    var currentdir = Titanium.Filesystem.getApplicationDataDirectory();
    
    — answered May 5th 2010 by Daniel Lim
    permalink
    0 Comments
  • BTW,i tried this but it doesn't work, and doesn't prompt error either.

    var newdir = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory);
    Ti.API.info('DIR NAME = ' + newdir);
    newdir.createDirectory('new')
    
    — answered May 5th 2010 by Daniel Lim
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.