Just use the nodir
option when you call gulp.src
. This will actually test the files being read off the filesystem instead of relying on conventions that may hold today but not tomorrow.
In the following example, the debug()
in the dir
target will output files and directories. The debug()
in the nodir
target will output only files because it uses nodir
. Populate the directory foo
with files and subdirectories and you'll see the difference.
var gulp = require("gulp");
var debug = require("gulp-debug");
gulp.task("dir", function () {
return gulp.src("foo/**")
.pipe(debug());
});
gulp.task("nodir", function () {
return gulp.src("foo/**", { nodir: true })
.pipe(debug());
});
If you want to have one part of the tree include directories and another part exclude them then you can merge streams:
var es = require("event-stream");
gulp.task("nodir-multi", function () {
return es.merge(gulp.src("foo/**", { nodir: true }),
gulp.src("bar/**"))
.pipe(debug());
});
I don't think the convenience of having just one gulp.src
call justifies relying on *.*
and .*
to exclude directories. Version control systems often create directories what would match .*
(e.g. .git
, .svn
). Development tools also do the same (e.g. .deps
, .tmp.foo
).