File manager

File manager

This script started as a request (https://plus.google.com/+JaroslavGrochal/posts/2CRLTSe588K), but it is usable and maybe useful, so I’m sharing it as a separate post.

The script populates a panel with the files of a specified folder. You can launch the files and navigate opening folders or going ‘up’ the folder hierarchy.

It also lets you create new empty files and folders.

If someone want to improve it, here are a list of features currently unsupported but that will be a good addition: custom menu when long tapping, ability to delete items, custom icons for non-folder files, ability to create bookmarks and save the current path as a variable (or display it somewhere). And also a bit of optimization, the current script is optimized but can be a bit slow with folders with many items.

To set it up create a panel somewhere and check it’s id (long tap the panel, and the menu should say “Panel #00001a”, the id is ‘1a’) Then write this id on the script using the 0x prefix (second line: var containerId=0x1a) and change the default path if you want.

Important! The panel will be filled with the items. All things inside will be removed when the script runs.

I also highly recommend changing some properties of the panel: one column, 10-15 rows, disable snap to pages, enable scroll as far as the items go and set labels position at the right.

You may create a shortcut to run this script, that will open the default path, our you can add a different path as the data in the shortcut to create manual bookmarks.

]]>

2 Commentsto File manager

  1. Anonymous says:

    < ![CDATA[

    var path=”/”;


    var containerId=0x7b;





    //binds


    LL.bindClass(“java.io.File“);


    LL.bindClass(“java.io.FileWriter“);


    LL.bindClass(“android.os.Environment“);


    LL.bindClass(“android.webkit.MimeTypeMap“);



    var event=LL.getEvent();


    var scriptId=LL.getCurrentScript().getId();



    var path= event.getData() || event.getItem().getTag() || Environment.getExternalStorageDirectory()+path;




    var current=new File(path);



    if(event.getItem().getTag(“createFile”)!=null){



    var name;


    if((name=prompt(“Name of file:”,””))!=null){


    var newfile=(new File(current,name));


    newfile.createNewFile();


    LL.startActivity(intentFromFile(newfile));


    }else return;



    }else if(event.getItem().getTag(“createDir”)!=null){



    var name;


    if((name=prompt(“Name of dir:”,””))!=null){


    var newfile=(new File(current,name));


    newfile.mkdir();


    current=newfile;


    }else return;



    }else if(current.isFile()){


    LL.startActivity(intentFromFile(current));


    return;


    }




    var files=current.listFiles();



    if(files==null){


    Toast.makeText(LL.getContext(),”Error loading folder “+path,Toast.LENGTH_LONG).show();


    return;


    }



    var container=LL.getContainerById(containerId);




    var items=container.getItems();


    for(var t=0;t< items.getLength();++t){


    container.removeItem(items.getAt(t));


    }



    files.sort(sortingFunction);



    var icon_folder=LL.createImage(“android”, “ic_menu_archive”);


    var icon_new=LL.createImage(“android”, “create_contact”);


    var intent= Intent.parseUri(“#Intent;component=net.pierrox.lightning_launcher_extreme/net.pierrox.lightning_launcher.activities.Dashboard;i.a=35;S.d=”+scriptId+”;end”,0);



    for(var t=-3;t< files.length;++t){



    var shr=container.addShortcut(“”, intent,0,0);


    shr.setCell(0,t+3,1,t+4,true);



    if(t==-3){


    shr.setTag(current.getParent());


    shr.setLabel(“UP”,true);


    shr.setImage(LL.createImage(“android”, “ic_menu_revert”));


    }else if(t==-2){


    shr.setTag(path);


    shr.setTag(“createDir”,”1″);


    shr.setLabel(“CREATE NEW DIR”,true);


    shr.setImage(icon_new);


    }else if(t==-1){


    shr.setTag(path);


    shr.setTag(“createFile”,”1″);


    shr.setLabel(“CREATE NEW FILE”,true);


    shr.setImage(icon_new);


    }else if(files[t].isFile()){


    shr.setTag(files[t].getPath());


    shr.setLabel(“File: “+files[t].getName(),true);


    }else{


    shr.setTag(files[t].getPath());


    shr.setLabel(“Dir: “+files[t].getName(),true);


    shr.setImage(icon_folder);


    }



    }



    container.getOpener().getContainer().setPosition(0,0);







    function intentFromFile(file){


    var intent = new Intent(Intent.ACTION_VIEW);


    intent.setDataAndType(Uri.fromFile(file),getMimeType(file.getName()));


    var j = Intent.createChooser(intent, “Choose an application to open with:”);


    return j;//startActivity(j);


    }




    function getMimeType(url)


    {


    var parts=url.split(“.”);


    var extension=parts[parts.length-1];


    var type = null;


    var mime = MimeTypeMap.getSingleton();


    if (extension != null) {


    type = mime.getMimeTypeFromExtension(extension);


    }


    return type;


    }





    function sortingFunction(a,b){


    if(a.isFile()!=b.isFile()){


    return a.isFile()?1:-1;


    }



    return a.getName().toLowerCase()>b.getName().toLowerCase()?1:-1;


    }

    ]]>

  2. Anonymous says:

    < ![CDATA[

    I should have probably said this before.


    The post request is https://plus.google.com/+JaroslavGrochal/posts/2CRLTSe588K by Jaroslav Grochal who had the idea, so, thanks!

    ]]>

Leave a Reply

Your email address will not be published. Required fields are marked *