How do I copy directories recursively with gulp?


I am trying to stage a project from a working directory to a server (same machine). Using the following code:


I would expect to see all the files copied. However it flattens the dir structure - all directories are copied but every file is placed in the root /var/www

Gulp seems like a great build tool but copying items should be a simple process surely?

This question is tagged with deployment gulp

~ Asked on 2014-07-30 13:25:00

The Best Answer is


Turns out that to copy a complete directory structure gulp needs to be provided with a base for your gulp.src() method.

So gulp.src( [ files ], { "base" : "." }) can be used in the structure above to copy all the directories recursively.

If, like me, you may forget this then try:

    return gulp.src(src, {base:"."})

~ Answered on 2014-07-30 13:25:00


The following works without flattening the folder structure:


The '**/*' is the important part. That expression is a glob which is a powerful file selection tool. For example, for copying only .js files use: 'input/folder/**/*.js'

~ Answered on 2014-12-11 22:25:54

Most Viewed Questions: