Dan Rivers
Dan Rivers

Reputation: 173

Delete files in applicationDataDirectory

In titanium, what is the best way to delete -specific- files in the applicationDataDirectory?

Upvotes: 2

Views: 3300

Answers (2)

Mohammad RafiS
Mohammad RafiS

Reputation: 46

Deleting a file is this simple ,

var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'delete_me.txt');
f.write('foo');
// make sure there's content there so we're sure the file exists
// Before deleting, maybe we could confirm the file exists and is writable
// but we don't really need to as deleteFile() would just return false if it failed
if (f.exists() && f.writeable) {
    var success = f.deleteFile();
    Ti.API.info((success == true) ? 'success' : 'fail'); // outputs 'success'
}

One of the best material on FileSystems in simple: https://wiki.appcelerator.org/display/guides/Filesystem+Access+and+Storage#FilesystemAccessandStorage-Deletingfiles

Upvotes: 1

Muhammad Zeeshan
Muhammad Zeeshan

Reputation: 8856

The best way will be simply:

var file = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory,filename);
if ( file.exists() ) {
     file.deleteFile();
}

For complete details Titanium.Filesystem.File.

Upvotes: 3

Related Questions