Titanium Community Questions & Answer Archive

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

Copy files to Documents directory on first run

In my app I added some code that will move a few folders from a source folder under images into the Documents folder when the app first runs.

The move works perfectly in the simulator, but does not work on an iPhone (running iOS 4.0.1).

Is this:

  • a bug?
  • a permissions loophole that the simulator is not supposed to allow?
  • altogether the wrong way to go about adding initial data to the Documents folder in the first place?
— asked July 26th 2010 by Ted Haeger
  • documents
  • file
  • ti.filesystem.file
  • titanium.filesystem.file
0 Comments

3 Answers

  • I'll answer my own question…

    Apparently, it is a permissions loophole. The Simulator allows something that the phone does not.

    This article gave me a different way to go about accomplishing my objective:
    http://anovice.com/2010/07/16/installing-app-files-with-appcelerator-titanium/

    — answered July 28th 2010 by Ted Haeger
    permalink
    0 Comments
  • Since this post is no longer available in the web, I hunted it down at internet archive. Here is the bit that was helpful to me:

    if (Ti.App.Properties.getInt("installComplete") == null) {
         var imgOriginal = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory + "/image.jpg");
         var imgInstall = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory + "/image.jpg");
         imgInstall.write(imgOriginal);
    
         var dataOrig = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory + "/data.txt");
         var dataInstall = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory + "/data.txt");
         var dataContent = dataOrig.read();
         dataInstall.write(dataContent);
    
         Ti.App.Properties.setInt("installComplete", 1);
    }
    
    — answered February 22nd 2012 by Brian Wilhelm
    permalink
    0 Comments
  • hi, your question is very old may be you got answer till now but i wanna answer. there is a catch that you cannot move any file from resource directory , as move means you are removing it from resource directory, and titanium does not allow write permissions , so what you can do is read that whole file or directory and write it in the application data directory

    — answered April 18th 2013 by Ishan Singh
    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.