Show files from path string

Very simple macro that show files from string contains path (e.g. /var/www/).

function displayFiles() {
    /*Create components*/
    var os = Components.classes[";1"].getService(Components.interfaces.koIOs);
    var osp = Components.classes[";1"].getService(Components.interfaces.koIOsPath);
    var kodoc = komodo.koDoc;
    var scimoz = ko.views.manager.currentView.scimoz;
    var pos = scimoz.anchor;
    var line = scimoz.lineFromPosition(pos);
    var dirname = kodoc.file.dirName;
    var string = scimoz.getTextRange(scimoz.getLineEndPosition(line)-scimoz.lineLength(line), scimoz.getLineEndPosition(line));
    var matches = string.match(/(?:\'|\")([^\'\"]+)(?:\'|\")/g);
    function recursive_display_files(path) {
        var returned_array = [];
        if(!osp.exists(path)) return false; /*if path not exists*/
        if(!osp.isdir(path)) return false; /*if path not folder (e.g. /var/www/style.css - not folder :) ) */
        var list = os.listdir(path, {});
        for (k in list) {
            var file = list[k];
            var abs = osp.realpath(osp.join(path, file));
            if(osp.isdir(abs)) {
                returned_array[k] = file+"/";
            } else {
                returned_array[k] = file;
        return returned_array;
    for(i in matches) {
        var match = matches[i].replace(/(\"|\')/g, ""); //replace " and ' in matches
        if(match.indexOf(".") !== -1) {
            var path = osp.join(dirname, match);
        } else if(match !== "/") { //if path equal root directory of current file directory: set path to current directory of curent file 
            match = match.substr(1);  //else remove first "/"
            var path = osp.join(dirname, match);
        } else {
            var path = dirname;
        var array = recursive_display_files(path); //generate array of files
        if(array !== false && typeof(array[0]) !== "undefined") {
            var scimoz = ko.views.manager.currentView.scimoz;
            var sep = String.fromCharCode(scimoz.autoCSeparator);
            scimoz.autoCShow(0, array.join(sep));

I don’t know did this work on Windows, but I think must do.
Also, some bugs (I think it’s useronly, but anyway):

  1. When you trying to press enter to insert path - after path creates tab or 4 spaces.
  2. Folder with spaces are not work (display only first word).
  3. If folder is empty - tooltip will be generated but without any items. fixed
  4. In some times path cut not correctly. I’m work on it. fixed. Hate math!11!
    Don’t forget set keybinding for macro :smile:

Hey Defman, this is exactly why we have the Resources section :slight_smile: Would you mind submitting your macro there?

The Customization category is meant mostly to discuss customization techniques.

My bad, sorry :smile:
Okay, I submit my macro to resources :smile: