Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // The directory to search
- var directory = path.join("some/directory");
- global.results = [];
- // Collect all the audio files in the user's music library
- audioManager.getMusicFiles = (dir) => {
- // Collection of the music files
- // Read into the directory
- fs.readdirSync(dir).forEach(function (file) {
- var fstats = {};
- // Add it to the results only if the file is an audio file
- if ( file.split(".").pop() == "mp3" ) {
- // The filename property of the file
- fstats.filename = path.basename(file);
- // The real directory of the file
- fstats.fpath = path.join(dir, file);
- // Append the findings to the results array
- results.push(fstats);
- }
- if ( fs.statSync(path.join(dir, file)).isDirectory() ) {
- return audioManager.getMusicFiles(path.join(dir, file)); // Also scan that directory for music files
- }
- });
- };
- audioManager.getMusicFiles(directory);
- /** Returns unordered on console
- [
- {"filename": "01. Intro.mp3", "fpath":
- "C:\Users\Libby\Music\Azizi Gibson - Memoirs Of The Reaper\01. Intro
- (2).mp3"
- },
- { "filename": "02. Happy.mp3", "fpath":
- "C:\Users\Libby\Music\Azizi Gibson - Memoirs Of The Reaper\01. Intro
- (3).mp3"
- }
- ]
- But putting them into a HTML ELement they become unordered **/
Add Comment
Please, Sign In to add comment