O'Reilly logo

Appcelerator Titanium Smartphone App Development Cookbook - Second Edition by Jason Kneen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Safely deleting saved files from the filesystem

We can create these files and write them to our local phone storage, but what about deleting them? In this recipe, we'll explain how to safely check for and delete files using the Ti.Filesystem.File namespace.

How to do it...

In your app.js file, before you create tab2, add the following button code with an event listener. This will be our trash button and will call the delete function on the currently selected image:

//create trash button
var buttonTrash = Ti.UI.createButton({
    width: Ti.UI.SIZE,
    height: Ti.UI.SIZE,
    right: 25,
    bottom: 25,
    title: 'Delete',
    zIndex: 2,
    visible: false
});
//create event listener for trash button
buttonTrash.addEventListener('click', function(e){
    
});

We add an extra line ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required