Ankush Verma

Ankush Verma

  • NA
  • 187
  • 15.4k

Upload CSV files.

Jan 9 2023 5:44 AM

Hello everyone I have use papaparse library for read csv data it's working fine . But I have face a issue how to read multiple files.


Answers (3)

3
Amit Mohanty

Amit Mohanty

  • 16
  • 51.7k
  • 6m
Jan 9 2023 7:09 AM

Check the below code this may help you.

$(document).ready(function() {
  var files = ['file1.csv', 'file2.csv', 'file3.csv'];
  var results = [];

  function readFile(index) {
    if (index >= files.length) {
      // All files have been processed
      console.log(results);
      return;
    }

    $.ajax({
      type: 'GET',
      url: files[index],
      dataType: 'text',
      success: function(data) {
        var csvData = Papa.parse(data).data;
        results.push(csvData);
        readFile(index + 1);
      }
    });
  }

  readFile(0);
});

 

Accepted Answer
3
Rajesh Gami

Rajesh Gami

  • 80
  • 24.4k
  • 1.3m
Jan 9 2023 9:22 AM
var files = Directory.EnumerateFiles("path", "*.csv");
foreach (string file in files)
{
    using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read))
    {
        // Use the file stream to read data.
    }
}
2
Aravind  Govindaraj

Aravind Govindaraj

  • 307
  • 5.9k
  • 306.1k
Jan 9 2023 8:52 AM

could you please refer this link 

https://medium.com/@kishanvikani/parse-multiple-files-using-papa-parse-and-perform-some-synchronous-task-2db18e531ede