Guest User

Untitled

a guest
Nov 21st, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. // The directory to search
  2. var directory = path.join("some/directory");
  3. global.results = [];
  4. // Collect all the audio files in the user's music library
  5. audioManager.getMusicFiles = (dir) => {
  6. // Collection of the music files
  7. // Read into the directory
  8. fs.readdirSync(dir).forEach(function (file) {
  9. var fstats = {};
  10. // Add it to the results only if the file is an audio file
  11. if ( file.split(".").pop() == "mp3" ) {
  12. // The filename property of the file
  13. fstats.filename = path.basename(file);
  14. // The real directory of the file
  15. fstats.fpath = path.join(dir, file);
  16. // Append the findings to the results array
  17. results.push(fstats);
  18. }
  19.  
  20. if ( fs.statSync(path.join(dir, file)).isDirectory() ) {
  21. return audioManager.getMusicFiles(path.join(dir, file)); // Also scan that directory for music files
  22. }
  23. });
  24. };
  25. audioManager.getMusicFiles(directory);
  26.  
  27. /** Returns unordered on console
  28. [
  29. {"filename": "01. Intro.mp3", "fpath":
  30. "C:\Users\Libby\Music\Azizi Gibson - Memoirs Of The Reaper\01. Intro
  31. (2).mp3"
  32. },
  33. { "filename": "02. Happy.mp3", "fpath":
  34. "C:\Users\Libby\Music\Azizi Gibson - Memoirs Of The Reaper\01. Intro
  35. (3).mp3"
  36. }
  37. ]
  38.  
  39. But putting them into a HTML ELement they become unordered **/
Add Comment
Please, Sign In to add comment