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
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(); }
-
You're missing the ().
It's: Titanium.Filesystem.getApplicationDataDirectory()
-
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();
-
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')