peter-vilja / gulp-clean

A gulp plugin for removing files and folders from given paths.
177 stars 21 forks source link

How to clean and backup a directory recursively? #12

Closed frace closed 10 years ago

frace commented 10 years ago

I use the following code to clean an entire build directory and try to backup it recursively. But what I end up with as a backup is only the base directories without their contents. Is that possible at all?

/**
 * Wipe the build directory and create a backup
 */
    clean = {
        run: require("gulp-clean"),
        command: "clean",
        source: config.basedir + "build/*",
        target: config.basedir + "backup/build." + helpers.timestamp.now
    };

    gulp.task(clean.command, function() {
        return gulp
            .src(clean.source, {read: true})
            .pipe(clean.run({force: false}))
            .pipe(gulp.dest(clean.target));
    });
peter-vilja commented 10 years ago

You can use source: config.basedir + "build/**/*"

clean = {
        run: require("gulp-clean"),
        command: "clean",
        source: config.basedir + "build/**/*",
        target: config.basedir + "backup/build." + helpers.timestamp.now
    };
frace commented 10 years ago

Thank you for the hint. That seems to work fine. :)