Skip to content

Instantly share code, notes, and snippets.

@cauld
Created December 11, 2010 00:59
Show Gist options
  • Select an option

  • Save cauld/737045 to your computer and use it in GitHub Desktop.

Select an option

Save cauld/737045 to your computer and use it in GitHub Desktop.
Demonstrates basic filesystem CRUD operations with Titanium
var dataToWrite = {"en_us":{"foo":"bar"}};
//NOTE: remember to use applicationDataDirectory for writes
var newDir = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,'mydir');
newDir.createDirectory();
Ti.API.info('Path to newdir: ' + newDir.nativePath);
var newFile = Titanium.Filesystem.getFile(newDir.nativePath,'newfile.json');
//Stringify the JavaScript object we created earlier and write it out to the new file
newFile.write(JSON.stringify(dataToWrite));
var newFile = Titanium.Filesystem.getFile(newDir.nativePath,'newfile.json');
var resources = JSON.parse(newFile.read().text);
resources.en_us.foo = 'baz'; //bar becomes baz
newFile.write(JSON.stringify(resources));
//We already have references to the file and directory objects.
//We just need to call their cooresponding delete methods.
newFile.deleteFile();
newDir.deleteDirectory();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment