Guest User

Untitled

a guest
Jan 21st, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. const path = require('path');
  2. const fs = require('fs');
  3.  
  4. //joining path of directory
  5. const directoryPath = path.join(__dirname, 'Sales_Rep_Files');
  6.  
  7. //passing directoryPath and callback function
  8. fs.readdir(directoryPath, (err, files) => {
  9.  
  10. //handling error
  11. let Rep;
  12. if (err) throw err;
  13. console.log(files);
  14.  
  15. //read file for the rep-info json file
  16. fs.readFile('Rep-Info.json' ,(err,data) => {
  17. if (err) throw err;
  18. Rep = JSON.parse(data);
  19. console.log(Rep);
  20.  
  21. });
  22. // append the json file
  23. fs.appendFile("./final-result.json", JSON.stringify(files, null, 4),(err) => {
  24. if(err) throw err;
  25. console.log(err);
  26. })
  27. });
  28.  
  29.  
  30.  
  31. // attempt to compare the csv file to the json file.
  32.  
  33.  
  34. // long way would be to write a very long array.
  35.  
  36. // let arr = [{
  37. // id: 'Jeff_May_5807757.csv',
  38. // name: 'rev.jeffmay@gmail.com'
  39. // }, {
  40. // id:'' ,
  41. // name: ''
  42. // }]
  43.  
  44. // let result = arr.map(person => ({ value: person.id, text: person.name }));
  45. // console.log(result)
  46. // })
Add Comment
Please, Sign In to add comment