Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

getFile vs createFile

Pardon my noobishness … but I don't grasp the difference between .getFile and .createFile

the kitchen sink seems to use .getFile to create a file … but I can't make that work.

Can somebody tell me what's wrong here?

Basically, I'm just trying to see if a file exists … and create it if it doesn't.

var f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'fwb.txt');
if (f.exists()) {
    label1.text = 'Welcome Back!';
} else {
    label1.text = 'Hello, and welcome!';
    f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'fwb.txt');
}
— asked September 7th 2010 by Richard Brents
0 Comments

1 Answer

  • Accepted Answer

    For me it works.
    Maybe you need to write something to the file.

    
     label1.text = 'Hello, and welcome!';
        f = Titanium.Filesystem.getFile(Titanium.Filesystem.applicationDataDirectory, 'fwb.txt');
        f.write('something');
    
    — answered September 7th 2010 by Dan Tamas
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.