Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy multiple files and keep the folder structure with Gulp

I am trying to copy files from one folder to another folder using Gulp:

gulp.task('move-css',function(){   return gulp.src([     './source/css/one.css',     './source/other/css/two.css'      ]).pipe(gulp.dest('./public/assets/css/')); }); 

The above code is copying one.css & two.css to the public/assets/css folder.

And if I use gulp.src('./source/css/*.css') it will copy all CSS files to the public/assets/css folder which is not what I want.

How do I select multiple files and keep the folder structure?

like image 746
NullPoiиteя Avatar asked May 06 '15 05:05

NullPoiиteя


People also ask

How do I copy files using Gulp?

var copy = require('gulp-copy'); gulp. task('copy-resources', function() { return gulp. src('./src/img/*. png') .

How do you copy multiple files from one folder to another?

To do this, click and hold your left mouse button on the top-left portion of where you want to start highlighting. Next, drag the box until the last file or folder is highlighted. Once the files are selected, they can be copied, cut, or dragged to another window to move them.

How do I copy a group of files?

Step 1: Click on the first file to be selected. Step 2: Hold down Ctrl and click on all the files that you want to select additionally. Step 2: Press the Shift key and click on the last file. Step 3: You have now selected all files at once and can copy and move them.

Can we copy multiple folders at the same time?

Drag & drop makes it incredibly easy to copy or move files and folders. If you need to copy a file to multiple folders, you can hold down the Ctrl key, and drag the file or folder on to each folder you want to copy it to.

How to copy specific file types while keeping directory structure in Linux?

Copy Specific File Types While Keeping Directory Structure In Linux If --parents option doesn't work, you can combine find command with cpio command to copy files keeping directory structure. $ find. -name '*.mp3' | cpio -pdm ~/ostechnix

What is gulp and how does it work?

Initially it could be a copy and paste by hand but this becomes very repetitive, but with ' gulp ' this can be made an automatic process every time you update the 'dist' folder. Now this tutorial is based on you already having knowledge of setting up projects via ' npm ' for example using frameworks such as ' angular ', ' vuejs '.

Can you copy a folder structure without files?

With the Xcopy feature in Windows 10, folder structures can be copied and pasted out of the way with an easy-to-use shortcut. Can You Copy A Folder Structure Without Files? We recommend copying the entire folder structure without copying files that have already been selected for the new financial year (tip).

Do copy files have to be duplicated with XCOPY?

Copy files will not have to be duplicated, however, when copying folder structures you may need to repeat them with Xcopy. With the Xcopy feature in Windows 10, folder structures can be copied and pasted out of the way with an easy-to-use shortcut.


1 Answers

To achieve this please specify base.

¶ base - Specify the folder relative to the cwd. Default is where the glob begins. This is used to determine the file names when saving in .dest()


In your case it would be:

gulp.task('move-css',function(){   return gulp.src([       './source/css/one.css',       './source/other/css/two.css'   ],  {base: './source/'})    .pipe(gulp.dest('./public/assets/')); }); 

Folder structure:

. ├── gulpfile.js ├── source │   ├── css │   └── other │       └── css └── public     └── assets 
like image 187
Anulal S Avatar answered Sep 20 '22 19:09

Anulal S