0
votes

Im currently working on a simple file-explorer with NW.js Im developing on a linux-machine and there it works fine until now, but i tested it on a windows-system at work and there is a problem with listing all files in a directory. I developed it to work on both systems (i thought) here“s a link to my repo please note the file: js/main.js where i set the seperator-variable to be "\" on windows platforms (in function: getRootDir()).

In JS this:

alert("\\");

gives me: "\"

isnt that the seperator for windows?

Any help would be appreciated.

1
why don't just use "/" separator for both platforms? - exoddus
it doesnt work both ways - but to be more specific: it works only (both ways) with one or 2 folders and 2 files the rest is ignored. I wrote a test-script to give me everything in root, and that worked. Any ideas? - Wolfgaung
Rather than figuring out the path separator yourself, let node handle it. Try wrapping your path in path.resolve (log it in console to double-check). See also gist.github.com/domenic/2790533 - Mar
Thanks i already solved it on win the rootdir should be: "C:\\" --> "C:\" and on linux its simply "/" The seperator is win: "\\" on linux: "/" i figured out that displaying the root-dir was not the problem , but to display images on win you need to specify the path like i wrote it. Hope this will help somebody. - Wolfgaung

1 Answers

1
votes

I was playing around a bit and found out that the async one works and the sync one doesnt - here the async one:

        fs.lstat(rootElement.path + seperator + file, function(err, stats) {
            if (err) {throw err;}

            if (stats.isDirectory()) {
                createFolderView(rootElement, file);
            } else {
                createFileView(rootElement, file);
            }
        });

and here the sync one:

if (fs.lstatSync(rootElement.path + seperator + file).isDirectory()) {
   createFolderView(rootElement, file);
} else {
   createFileView(rootElement, file);
}

but shouldnt work both the same way - or am i missing something?