Titanium Community Questions & Answer Archive

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

Delete file from Resources directory

How can I delete file that is somewhere in resources directory?

Below you can see my folder structure:

var filePath = Ti.Filesystem.resourcesDirectory +
 Ti.Filesystem.separator + 'app' +
 Ti.Filesystem.separator + 'views' +
 Ti.Filesystem.separator + 'WebViewFolder' +
 Ti.Filesystem.separator + 'images' +
 Ti.Filesystem.separator + 'image.png'

var file = Ti.Filesystem.getFile(filePath);

Ti.API.info(file.exists());
file.deleteFile();
Ti.API.info(file.exists());

And this is the output:

[INFO] 1
[INFO] 0

But even if it says 0 which means that the file is deleted, I see the file in folder structure and on application restart I get the same output:

[INFO] 1
[INFO] 0

Files that I am creating and deleting has to be on that location because I am referencing them from inside WebView's javascript code.

This is the full folder structure:

Resources
    - app
        - views
            - WebViewFolder
                - html
                    - index.html
                - js
                    - file.js 
                        - here I can reference image like:
                        var image = new Image();
                        image.src = "../images/image.png"
                - images
                    - image.png

file.js sees only the WebViewFolder and can't see file that are somewhere else (Titanium.Filesystem.applicationDataDirectory)

Why can't I just simply create/delete files in that images folder?

iPhone, Titanium SDK 1.8.1

— asked February 8th 2012 by Dino Bartosak
  • delete
  • filesystem
  • ios
  • iphone
  • resources
2 Comments
  • Hello,

    did you restart the app inside the emulator or from the Ti Studio? Just wondering…

    Best,

    Mauro

    — commented February 8th 2012 by Mauro Parra
  • I just restart it with Ti Studio. I see from answer below that it is readonly directory… it sucks.

    — commented February 8th 2012 by Dino Bartosak

1 Answer

  • Accepted Answer

    The whole Resources folder is readonly.. it may work on the simulator, but on the device it will cause a permission error

    — answered February 8th 2012 by Raul Riera
    permalink
    4 Comments
    • Bu how about Bounty Hunter application from demos.
      Filesystem documentation says that applicationDataDirectory is readonly.

      And in Bounty Hunter application there is a piece of code that does this:

      Ti.Media.openPhotoGallery({
          success:function(event) {
              var image = event.media;
              imgView.image = image;    
              //save for future use
              var f = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory,'photo'+_bounty.id+'.png');
              f.write(image); // HERE IT WRITES IN applicationDataDirectory but in documentation it says that it is readonly??
              bh.db.(_bounty.id,f.nativePath);
      },
      .....
      

      — commented February 8th 2012 by Dino Bartosak
    • applicationDataDirectory is read/write the resources directory is the one that is read only… due note that the applicationDataDirectory is no where to be found on your "files" you need to move whatever files you want to work with from the Resources folder to that "Application Data" folder and then start doing what you want to do

      — commented February 8th 2012 by Raul Riera
    • Ti.Filesystem.resourcesDirectory = readonly
      Ti.Filesystem.applicationDataDirectory = read/write

      — commented February 8th 2012 by Raul Riera
    • OK, tnx. I'll have to find a workaround form my problem then.

      — commented February 8th 2012 by Dino Bartosak
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.