Skip to content

Instantly share code, notes, and snippets.

@milon120203
Created June 25, 2018 17:35
Show Gist options
  • Save milon120203/2a43488632494b591dd4613e309d95e1 to your computer and use it in GitHub Desktop.
Save milon120203/2a43488632494b591dd4613e309d95e1 to your computer and use it in GitHub Desktop.
File name changing with the content which will be changed two times.
var window = Ti.UI.createWindow({
layout:'vertical',
});
window.open();
var dir = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory);
var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'file_A.txt');
f.write('first value ');
var button = Titanium.UI.createButton({
title : 'one',
top : 10,
width : 100,
height : 50
});
button.addEventListener('click', function(e) {
var success = f.rename('file_B.txt');
if (success == true) {
Ti.API.info('File has been renamed');
} else {
Ti.API.info('File has NOT been renamed');
}
Ti.API.info('f.name = ' + f.name);
f.write('second value');
Ti.API.info('File_A updated by : ' + f.read());
var newf = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,
'file_B.txt');
Ti.API.info('File name is ' + newf.name);
Ti.API.info('File reading ::' + newf.read());
});
window.add(button);
var button1 = Titanium.UI.createButton({
title : 'two',
top : 10,
width : 100,
height : 50
});
button1.addEventListener('click', function(e) {
var success = f.rename('file_B.txt');
if (success == true) {
Ti.API.info('File has been renamed');
} else {
Ti.API.info('File has NOT been renamed');
}
Ti.API.info('f.name = ' + f.name);
f.write('second value');
Ti.API.info('File_A updated by : ' + f.read());
var newf = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,
'file_B.txt');
Ti.API.info('File name is ' + newf.name);
Ti.API.info('File reading ::' + newf.read());
});
window.add(button1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment