There is certainly such a simple answer to this that I can't find anyone that's asked it before:
What globbing pattern to include all the files in a folder but ignore ALL subfolders?
gulp.src('*') includes all files and folders. I just want the files and would rather not have to exclude the folders individually.
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
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With