Question

I'm writing a small app that needs to list files from multiple paths.

Iv tried to do somthing like this but its only shows me the first path.

Any clue why is that?

Here is the code:

var wsh = new ActiveXObject("WScript.Shell");
var FSO = new ActiveXObject("Scripting.FileSystemObject");

function window.onload() {
    var s = "";
    var paths = FSO.OpenTextFile("bin\\paths.txt")

    while (!paths.AtEndOfStream) {
    content = paths.ReadLine();
    s += content;
    loadMediaFolders(s);
    }
    stat.innerHTML= s;
}

function loadMediaFolders(wathPath) {
var str = "";
    var folder = FSO.GetFolder(wathPath);
        var mainFolders = new Enumerator(folder.SubFolders);
            for (; !mainFolders.atEnd(); mainFolders.moveNext()) {

                var FolderPath = mainFolders.item().Path;

                var files = FSO.GetFolder(FolderPath);
                var sbFiles = new Enumerator(files.Files);

                for (; !sbFiles.atEnd(); sbFiles.moveNext()) {
                var FilleName = sbFiles.item().Name;

                str += FilleName;
                }
            }
    stat.innerHTML= str;
}

This is how the paths are stored inside the file:

F:\\stuff\\Media\\Movies\\
D:\\Media\\Movies\\
Was it helpful?

Solution

In the loop reading the folder paths, you are concatenating the paths before passing them to loadMediaFolders(...). The first one will work since s will be F:\stuff\Media\Movies\, the second time s will be F:\stuff\Media\Movies\D:\Media\Movies\.

Try something like this

while (!paths.AtEndOfStream) {
    content = paths.ReadLine();
    loadMediaFolders(content);
}

loadMediaFolders(...) already writes the result to stat.innerHtml, so that line can be removed too. Keep in mind that you might be overwriting all of stat.innerHtml, when you really wanted to concatenate the results, in loadMediaFolders(...).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top