Thursday, October 20, 2022

[FIXED] How to get all files path from directory in node.js

Issue

I'm working on retrieve images from csv file. Right now, i could manage.

  • retrieve data base64 images from a csv file
  • convert base64 image & export it as a .jpeg files in a directory

which the directory is like this

├── assets
    ├── export
        ├── img1.jpeg
        ├── img2.jpeg
        ├── img3.jpeg
        ├── ...

how do i get all imgs path from the export directory?.


Solution

Well looking at the node doc is like this.

const fs = require('fs');

const dirnameExportImg = './assets/export'

fs.readdir(dirnameExportImg, function (err, files) {
  if (err) {
    console.log(err)
  }
  files.map(
    (file) => { console.log(file) }
  )
})


Answered By - Yoarthur
Answer Checked By - Candace Johnson (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.