Wednesday 25 April 2018

Using fs to get dir and file names into a JS object

Imagine you have a simple directory and file structure that looks like this.├── dir1│ ├── fileA│ ├── fileB│ └── fileC├── dir2│ ├── fileD│ ├── fileE│ └── fileF└── dir3├── fileG├── fileH└── fileIYou want to scan these directories and return an array of JS objects that looks like this[{directory: dir1, files: [fileA, fileB, fileC]}, {directory: dir2, files: [fileD, fileE, fileF]}, {directory: dir1, files: [fileG, fileH, fileI]}]How would you go about achieving this with node?

Submitted April 25, 2018 at 10:55AM by G_pounder

No comments:

Post a Comment