Titanium Community Questions & Answer Archive

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

remove local directory

Hello everyone

I created a new dir in my app directory with

var parent = Titanium.Filesystem.getApplicationDataDirectory();
var new_folder = Titanium.Filesystem.getFile(parent, 'atlas');
new_folder.createDirectory();

Now i would to delete this directory and all it's content, I tryied whit

new_folder.removeDirectory();

but it seems don't work..!
Any help! Thank you!

— asked November 28th 2010 by Stefano Di Luca
  • delete
  • directory
  • file
  • files
  • filesystem
  • filesystem.getfile
0 Comments

4 Answers

  • Accepted Answer

    According to the doc, by default deleteDirectory is not recursive. So if you have subfolders (or if the directory is not empty ?), I suppose you need to use the optional boolean parameter :

    new_folder.deleteDirectory(true);

    http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Filesystem.File.deleteDirectory-method.html

    — answered November 29th 2010 by Pascal PLUCHON
    permalink
    1 Comment
    • Thank you! it work!

      — commented November 29th 2010 by Stefano Di Luca
  • Stefano

    Just a small amendment to your code, and I think it will work. According to the Titanium.Filesystem.File docs, it's deleteDirectory() rather than removeDirectory().

    Cheers

    — answered November 28th 2010 by Paul Dowsett
    permalink
    1 Comment
    • Remember to click on the link for deleteDirectory() to find out how to use it. ;)

      — commented November 29th 2010 by Paul Dowsett
  • Sorry, it's true bu directory it's still here!

    — answered November 28th 2010 by Stefano Di Luca
    permalink
    0 Comments
  • I have the same problem but i want to delete only the subdirectory when i use true with deleteDirectory i have /pdf/low all deleted any help thanks.

    ~~~
    var parent =Titanium.Filesystem.applicationDataDirectory+'pdf';    
    var PdfDir = Titanium.Filesystem.getFile(parent,'low');
    pdfDir.deleteDirectory(true);
    ~~~
    
    — answered April 16th 2012 by guellai farid
    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.