PIXI.LOADER Err on path from nwJS, how i can normalize path ?

hi guy, i have a error when i try inject a JSON in pixi loader

i get my JSON files path from nwJS with this following code.
it give me ex: "C:\Users\jonle\Documents\Games\A NEW FANTASTIQUE TIME TOME1\SSA\Decoration\tree\tree1\tree1.json"

how i can normalize path for use in pixiLoader without use regex ?
i take a look with command path.normalize(path)
https://nodejs.org/docs/latest/api/path.html#path_path_resolve_paths
but it not work.
pixi loader have a native way to take win32 path ?
Or do you have suggest for me (without Regex)


PHP:
(function(){
    var fs = require("fs");
    var path = require("path");
    var gameDir = path.dirname(process.mainModule.filename);
    path.sep = '/'
    
    var walkFolder = function(dir, done) {
        var results = [];
        fs.readdir(dir, function(err, list) {
          if (err) return done(err);
          var pending = list.length;
          if (!pending) return done(null, results);
          list.forEach(function(file) {
            file = path.resolve(dir, file);
            
            fs.stat(file, function(err, stat) {
              if (stat && stat.isDirectory()) {
                walkFolder(file, function(err, res) {
                  results = results.concat(res);
                  if (!--pending) done(null, results);
                });
              } else {
                (file.indexOf('.json')>0) && results.push(file); // push only .JSON ext
                if (!--pending) done(null, results);
              }
            });
          });
        });
      };
    walkFolder(gameDir+'/SSA', function(err, results) {
        if (err) throw err;
        pixiPME.JSON_LIBRARY = results;
        pixiPME.nwJSLoadComplette = true; pixiPME.canStartPixiLoad();
      });
})();

////////////////////////////////////////////////////////////////////////////////////////////////
// READY TO INITIALISE LOADER FOR ALL DATA JSON LIBRARY
_pixiPME.prototype.initialise = function() {
    // load all json libs
    PIXI.loader.add(this.JSON_LIBRARY[0])//GET ERROR HERE BECAUSE PATH ARE IN WIN32 FORMAT
    console.log('this.JSON_LIBRARY[0]: ', this.JSON_LIBRARY[0]);
    for(var f = 0; f<this.JSON_LIBRARY.length;f++){
        //PIXI.loader.add(this.JSON_LIBRARY[f]); //  ADD JSON RESSOURCE
        break
    }

JSON_LIBRARY give me error because path are in win32
I'm not entirely sure what normalize path means. Is it like, setting a common filepath for multiple files?
I'm not entirely sure what normalize path means. Is it like, setting a common filepath for multiple files?
ok sorry, ex: nwJS give me
"C:\Users\jonle\Documents\Games\A NEW FANTASTIQUE TIME TOME1\SSA\Decoration\tree\tree1\tree1.json"
but i need a native way to get a non win32 path like this, but in nwJS, because i want avoid use Regex or js method
"C:/Users/jonle/Documents/Games/A NEW FANTASTIQUE TIME TOME1/SSA/Decoration/tree/tree1/tree1.json"
Are you sure that your problem isn't caused by the spaces in the directory name?
Because that is a much greater Problem in my opinion, spaces are not allowed under networking rules for filepaths and filenames.
Code:
function filepathConvert (path) {
var spl = path.split('\');
var str = "";
for (var i in spl) {
str += spl[i];
if (i < spl.length - 1) str += "/"
}
return str;
}
What about this conversion function?

With regex it would be much faster though.
Code:
function filepathConvert (path) {
return path.replace (/\/g, "/");
}
Are you sure that your problem isn't caused by the spaces in the directory name?
Because that is a much greater Problem in my opinion, spaces are not allowed under networking rules for filepaths and filenames.
@Andar
nop the loader auto formate '%20' for space

// example this work
PHP:
PIXI.loader.add(
"C:/Users/jonle/Documents/Games/A NEW FANTASTIQUE TIME TOME1/SSA/Decoration/tree/tree1/tree1.json"
)

but this not work
PHP:
// path result from nwjs
PIXI.loader.add(
"C:\Users\jonle\Documents\Games\A NEW FANTASTIQUE TIME TOME1\SSA\Decoration\tree\tree1\tree1.json"
)

thank @Poryg , yes i will use regex or js method only if i have no choice.
What interest me its a way to do this , but reversed.
https://nodejs.org/docs/latest/api/path.html#path_path_normalize_path
or a similar way.

if i understand i need to change the path.sep
https://nodejs.org/docs/latest/api/path.html#path_path_sep
ok i have no choice, after search a hour.
So solution,
PHP:
(file.indexOf('.json')>0) && results.push(file.replace(/\\/g, "/")); // push only .JSON extension
thank solved
Thread closed IgnoreMe

Original thread: https://forums.rpgmakerweb.com/threads/pixi-loader-err-on-path-from-nwjs-how-i-can-normalize-path.91511/