如何在javascript中迭代本地目录

如何在javascript中迭代本地目录,javascript,html,csv,d3.js,Javascript,Html,Csv,D3.js,我在一个目录中有几个文件,我使用wamp服务器,有没有一种方法可以对它们进行迭代,我可以调用这个函数d3.csvdata.csv,functionerror,data{为每个文件 小片段: <!DOCTYPE html> <meta charset="utf-8"> <style> body { font: 10px sans-serif; } .axis path, .axis line { fill: none; stroke: #000;

我在一个目录中有几个文件,我使用wamp服务器,有没有一种方法可以对它们进行迭代,我可以调用这个函数d3.csvdata.csv,functionerror,data{为每个文件

小片段:

<!DOCTYPE html>
<meta charset="utf-8">
<style>

body {
  font: 10px sans-serif;
}

.axis path,
.axis line {
  fill: none;
  stroke: #000;
  shape-rendering: crispEdges;
}

.point {
  stroke: #000;
}

</style>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js"></script>
<script>

var margin = {top: 20, right: 20, bottom: 30, left: 40},
    width = 960 - margin.left - margin.right,
    height = 500 - margin.top - margin.bottom;

var x = d3.scale.linear()
    .range([0, width]);

var y = d3.scale.linear()
    .range([height, 0]);

var z = d3.scale.category10();

var svg = d3.select("body").append("svg")
    .attr("width", width + margin.left + margin.right)
    .attr("height", height + margin.top + margin.bottom)
  .append("g")
    .attr("transform", "translate(" + margin.left + "," + margin.top + ")");

d3.csv("data.csv", function(error, data) {
  if (error) throw error;

  // Compute the series names ("y1", "y2", etc.) from the loaded CSV.
  var seriesNames = d3.keys(data[0])
      .filter(function(d) { return d !== "x"; })
      .sort();

  // Map the data to an array of arrays of {x, y} tuples.
  var series = seriesNames.map(function(series) {
    return data.map(function(d) {
      return {x: +d.x, y: +d[series]};
    });
  });

  // Compute the scales’ domains.
  x.domain(d3.extent(d3.merge(series), function(d) { return d.x; })).nice();
  y.domain(d3.extent(d3.merge(series), function(d) { return d.y; })).nice();

  // Add the x-axis.
  svg.append("g")
      .attr("class", "x axis")
      .attr("transform", "translate(0," + height + ")")
      .call(d3.svg.axis().scale(x).orient("bottom"));

  // Add the y-axis.
  svg.append("g")
      .attr("class", "y axis")
      .call(d3.svg.axis().scale(y).orient("left"));

  // Add the points!
  svg.selectAll(".series")
      .data(series)
    .enter().append("g")
      .attr("class", "series")
      .style("fill", function(d, i) { return z(i); })
    .selectAll(".point")
      .data(function(d) { return d; })
    .enter().append("circle")
      .attr("class", "point")
      .attr("r", 4.5)
      .attr("cx", function(d) { return x(d.x); })
      .attr("cy", function(d) { return y(d.y); });
});

</script>

提前感谢

假设此代码在浏览器中运行,并且假设您谈论的是用户的目录,即客户端,则无法直接迭代目录列表。但是,您可以使用多文件输入并允许用户选择目录中的所有文件。其语法类似于:

然后给定对输入元素的引用,elem.files将为您提供表示文件的对象列表


有关更多信息,请参阅。

我使用的是wamp服务器,因此我的文件存储在其中。是否也不可能使用wamp?