user3147268 user3147268 - 1 year ago 112
Javascript Question

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

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
I get
and the whole
outputs only a large dictionary without any filepaths.

Answer Source

According to the gulp documentation on gulp.src (

gulp.src(globs[, options])

Emits files matching provided glob or an array of globs. Returns a stream of Vinyl files that can be piped to plugins.


glob refers to node-glob syntax or it can be a direct file path.


Type: String or Array

Glob or array of globs to read.


Type: Object

Options to pass to node-glob through glob-stream.

gulp adds some additional options in addition to the options supported by node-glob and glob-stream

So it seems you need to look in further on this. Otherwise this maybe helpful Get the current file name in gulp.src()