From 3cc71bbe9dc7498338bdd12a5a1d3d01bb8cfc73 Mon Sep 17 00:00:00 2001 From: danbulant Date: Sun, 23 Jun 2019 12:40:18 +0200 Subject: [PATCH] Fix directory listing (node.js) --- files.js | 7 +++---- html/node.js | 2 +- main.js | 17 +++++++++++++---- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/files.js b/files.js index 881b368..0a2ef0d 100644 --- a/files.js +++ b/files.js @@ -6,10 +6,9 @@ module.exports = { path: require('path'), walkDir: function(dir, callback){ fs.readdirSync(dir).forEach( f => { - let dirPath = path.join(dir, f); - let isDirectory = fs.statSync(dirPath).isDirectory(); - isDirectory ? - this.walkDir(dirPath, callback) : callback(path.join(dir, f)); + let dirPath = path.join(dir, f); + let isDirectory = fs.statSync(dirPath).isDirectory(); + callback(path.join(dir, f)); }); } } diff --git a/html/node.js b/html/node.js index 61bcabf..5f8cc17 100644 --- a/html/node.js +++ b/html/node.js @@ -24,7 +24,7 @@ if(typeof require != undefined){ ipcRenderer.on('listFiles', (event, arg) => { console.log(arg); }) - ipcRenderer.send('listFiles', '/'); + ipcRenderer.send('listFiles', 'C:\\Users\\Dan\\Documents\\GitHub\\console-hub'); } else { //no NODE integration, propably browser access } diff --git a/main.js b/main.js index 73d2f0b..6371b02 100644 --- a/main.js +++ b/main.js @@ -175,11 +175,20 @@ ipcMain.on('fullscreen', (event, arg) => { }) ipcMain.on('listFiles', (event, arg) => { console.log('Listing all files and directories in ' + arg); - dirs = files.walkDir(arg, function(filePath) { - const fileContents = fs.readFileSync(filePath, 'utf8'); - console.log(filePath, fileContents); + dirs = []; + counter = 0; + files.walkDir(arg, function(filePath) { + console.log(filePath); + dirs[counter] = filePath; + counter++; }); - event.reply('listFiles', fileContents); + counter = 0; + dirs.sort(function(a, b){ + if(a < b) { return -1; } + if(a > b) { return 1; } + return 0; + }) + event.reply('listFiles', dirs); }) app.setAppUserModelId(process.execPath)