mirror of
https://github.com/danbulant/console-hub
synced 2026-05-19 04:18:45 +00:00
Fix directory listing (node.js)
This commit is contained in:
parent
1d51db1ec7
commit
3cc71bbe9d
3 changed files with 17 additions and 9 deletions
7
files.js
7
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));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
17
main.js
17
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)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue