How to get the path of the folder which exists in external sdcard?

You must Login before you can answer or comment on any questions.

Hi all, i'm unable to get the path of the folder which exists in the external sdcard. I'm using the following code.....

var filename='xyz';//.......It is folder name
  var file= Titanium.Filesystem.getFile(Titanium.Filesystem.externalStorageDirectory,filename);
  alert("file path is"+file)   //here i'm getting alert as..........[object file]
  if (file.exists()) 
    {
        alert('file exists');
    }
    else
    {
        alert("file not exists");
    }
I created the folder name in the external sdcard as 'xyz'. But always i'm getting 'false' value for the file.exists().

Any help would be appreciated.

2 Answers

hello,

Try this

var dir = Titanium.Filesystem.getFile(Titanium.Filesystem.externalStorageDirectory);
    Ti.API.info('external directoryListing = ' + dir.getParent().getDirectoryListing());
You can also refer link

— answered 10 months ago by Moiz Chhatriwala
answer permalink
2 Comments
  • I tried this before only, but here i'm getting all the folders exists in the internal sdcard.......but i want to get all the folders of the external sdcard

    — commented 10 months ago by Gopinath Chokkarapu

  • try getting file within the folder by

    Ti.Filesystem.getFile('file:///sdcard/foldername', fileName)

    — commented 10 months ago by Moiz Chhatriwala

This did the trick for me, at least with SDK 3.1.0:

var dir = Ti.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory);
Ti.API.info('external sdcard path = ' + dir.getParent().getNativePath());

Your Answer

Think you can help? Login to answer this question!