Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List all files in array with gulp.src()

I'm trying to create an index of all file(path)s within a given folder. So far I worked with gulp.src(filePath) to achieve that. According to this blog post, it should work:

gulp.src(files) is a string or array containing the file(s) / file paths.

My current code:

gulp.task("createFileIndex", function(){
    var index = gulp.src(['./content/**/*.*']);
    console.log("INDEX:", index[0]);
});

By outputing the returned values of gulp.src() with index[0] I get undefined and the whole index outputs only a large dictionary without any filepaths.

like image 430
user3147268 Avatar asked Aug 02 '15 11:08

user3147268


2 Answers

The current solution is:

var gulp = require('gulp');
var debug = require('gulp-debug');

gulp.src(sources)
  .pipe(debug());
like image 179
Blitz Avatar answered Nov 03 '22 09:11

Blitz


As the OP stated in a comment, a simple solution to this problem would be to use fs.readdirSync instead of gulp.src:

fs = require("fs");
fs.readdirSync(directoryPath); // ["file1", "file2"]
like image 8
Chase Sandmann Avatar answered Nov 03 '22 07:11

Chase Sandmann