NodeJS
04-February-2024

How to list all the files in a folder and its sub-folders in CSV format?

NodeJSFiles ListCSVfspath

Files List | Hero Image

In this blog, we will explore how can we get the list of all the files in a folder and its sub-folder in CSV format using NodeJS APIs.



Repository Link

https://github.com/techwithmks/file-paths-to-csv



Steps to Follow

Follow the below-mentioned steps to quickly get the files list

  1. Install NodeJS in your system. Get a quick glance on this link to know how to install NodeJS in your system.
  2. If you have git installed in your system, clone above-mentioned repository using the following command.
    git clone https://github.com/techwithmks/file-paths-to-csv
    Git

    Alternatively, you can download the repository itself. Just go to the repository link and click on the green coloured "Code" dropdown button.

    File Paths List CSV | Github | s-mani.in
    Download option at the github page
  3. Go to config.js file, and add the source and destination absolute paths.
    const filePathsConfig = {
      source: "",
      destination: "",
    };
    JavaScript
    • source implies the folder's absolute path whose files need to be listed.
      E.g. C:/Users/<user-name>/Documents/
    • destination implies the csv absolute path of the CSV file where the output will be printed.
      E.g. C:/Users/<user-name>/Documents/output.csv
  4. Execute the following command in the terminal
    npm run start
    Bash

The output is printed in the csv file path provided in the destination key in the config.js.



References