mirror of
https://github.com/danbulant/console-hub
synced 2026-05-24 12:35:48 +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'),
|
path: require('path'),
|
||||||
walkDir: function(dir, callback){
|
walkDir: function(dir, callback){
|
||||||
fs.readdirSync(dir).forEach( f => {
|
fs.readdirSync(dir).forEach( f => {
|
||||||
let dirPath = path.join(dir, f);
|
let dirPath = path.join(dir, f);
|
||||||
let isDirectory = fs.statSync(dirPath).isDirectory();
|
let isDirectory = fs.statSync(dirPath).isDirectory();
|
||||||
isDirectory ?
|
callback(path.join(dir, f));
|
||||||
this.walkDir(dirPath, callback) : callback(path.join(dir, f));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ if(typeof require != undefined){
|
||||||
ipcRenderer.on('listFiles', (event, arg) => {
|
ipcRenderer.on('listFiles', (event, arg) => {
|
||||||
console.log(arg);
|
console.log(arg);
|
||||||
})
|
})
|
||||||
ipcRenderer.send('listFiles', '/');
|
ipcRenderer.send('listFiles', 'C:\\Users\\Dan\\Documents\\GitHub\\console-hub');
|
||||||
} else {
|
} else {
|
||||||
//no NODE integration, propably browser access
|
//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) => {
|
ipcMain.on('listFiles', (event, arg) => {
|
||||||
console.log('Listing all files and directories in ' + arg);
|
console.log('Listing all files and directories in ' + arg);
|
||||||
dirs = files.walkDir(arg, function(filePath) {
|
dirs = [];
|
||||||
const fileContents = fs.readFileSync(filePath, 'utf8');
|
counter = 0;
|
||||||
console.log(filePath, fileContents);
|
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)
|
app.setAppUserModelId(process.execPath)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue