list folder

283 views
Skip to first unread message

Daniel Bolik

unread,
May 19, 2016, 2:21:10 AM5/19/16
to DroidScript
Is there a way to filter out just folders using app.ListFolder?

I am able to filter by file type, but need to get just folders.

Example:
app.ListFolder("/sdcard/droidscript/","folder");

sankarshan dudhate

unread,
May 19, 2016, 3:27:43 AM5/19/16
to DroidScript
I don't think there is a away to achieve this without a little hack at the moment. It'd be worth putting a request for "Folder" option in the 'Tell Us What You Want Thread'.

sankarshan dudhate

unread,
May 19, 2016, 3:54:44 AM5/19/16
to DroidScript
Following code shows how you can get the array of folders in your default storage :

     

//Called when application is started.
function OnStart()
{
 Only_Folders = []; //an empty array
 
 //Get the path of special folder. helps us get default storage path
 base = app.GetSpecialFolder( "Music" );
 
 n1 = base.lastIndexOf("/");
 
 //cut the base path till the index n1+1
 pbase = base.substring(0,n1+1);
 
 lbase = app.ListFolder( pbase ); //list the default storage
 
 lsbase = lbase.toString(); //get the string representation of lbase
 
 labase = lsbase.split(","); //split lbase on ",". returns an array
 
 //Run the labase array through a loop which checks if an
 //item in the array is a file. If an item is a folder, add it to our
 //array Only_Folders.
 for(i=0; i<labase.length; i++) {
  exists = app.FolderExists( pbase + labase[i] );
  if(exists) Only_Folders.push(labase[i]);
 }
 
  alert(Only_Folders); //Alert the Only_Folders array.
}


John LaDuke

unread,
Jul 31, 2017, 5:14:32 PM7/31/17
to DroidScript
app.ListFolder returns an array, filter it. I.e:

app.ListFolder("/sdcard/Droidscript").filter( function(name){ return app.IsFolder("/sdcard/Droidscript/"+name); });

Symbroson

unread,
Aug 1, 2017, 2:42:02 AM8/1/17
to DroidScript
app.ListFolder already has a filter argument:
alert(app.ListFolder("/sdcard/Documents","*.txt").join("\n"))

John LaDuke

unread,
Aug 2, 2017, 7:57:10 AM8/2/17
to DroidScript
...which is limited to one file type at a time, i.e. "jpg". How would you filter for ALL image types less than 100k in size?

JustAnotherDude

unread,
Aug 2, 2017, 8:34:51 AM8/2/17
to DroidScript
just use "*.png,*.jpg,*.bmp" etc

Symbroson

unread,
Aug 2, 2017, 9:04:37 AM8/2/17
to DroidScript
I think also regex was possible since the last update - but I'm not sure - try it out

John LaDuke

unread,
Aug 2, 2017, 12:20:53 PM8/2/17
to DroidScript
Is that a guess or did you actually try it yourself?

John LaDuke

unread,
Aug 2, 2017, 12:22:24 PM8/2/17
to DroidScript
I tried a "regex" option but couldn't get it to work, any more suggestions?

Steve Garman

unread,
Aug 2, 2017, 12:58:01 PM8/2/17
to DroidScript

var list = app.ListFolder( "/sdcard/pictures", ".*\.jpg|.*\.png", 0, "regex,files" );

John LaDuke

unread,
Aug 2, 2017, 4:22:42 PM8/2/17
to DroidScript
Oh, so unlike JavaScript regex you MUST match all chars.

Steve Garman

unread,
Aug 3, 2017, 11:37:38 AM8/3/17
to DroidScript
I'm not quite sure what gives you that impression John.

Can you give us a sample of the type of regex you have in mind?

Reply all
Reply to author
Forward
0 new messages