31

Given the following source tree:

dev
 丨- psd
     丨- psd.psd
     丨- png.png
 丨- css
     丨- css.css
 丨- image
     丨- 1.jpg
     丨- 2.png
 丨html.html

How do I copy to the pub directory ignoring the psd folder as seen below?

pub
 丨- css
     丨- css.css
 丨- image
     丨- 1.jpg
     丨- 2.png
 丨html.html

I tried the following:

{
 expand: true,
 src: ['dev/**/*', '!dev/psd/**/*'],
 dest: 'pub/'
}

But this results in an empty psd directory

Atilla Ozgur
  • 14,339
  • 3
  • 49
  • 69
kimsagro
  • 15,513
  • 17
  • 54
  • 69

1 Answers1

65

Try following Gruntfile.js. It ignores psd directory. Solution found in following question.

module.exports = function(grunt) {

  // Project configuration.
  grunt.initConfig({
        copy: {
          main: {
            src: ['**/*',  '!**/psd/**'],
            expand: true,
            cwd: 'dev',
            dest: 'pub',
          }
    }
  });

  // Load the plugin that provides the "copy" task.
    grunt.loadNpmTasks('grunt-contrib-copy');

  // Default task(s).
  grunt.registerTask('default', ['copy']);

};

example setup.

mkdir gruntQuestion1
cd gruntQuestion1/
mkdir dev
mkdir dev/psd
mkdir dev/css
mkdir dev/image
touch dev/html.html
touch dev/psd/psd.psd
touch dev/psd/png.png
touch dev/css/css.css
touch dev/image/1.jpg
touch dev/image/2.png


atilla$ rm -rf pub/
atilla$ grunt
Running "copy:main" (copy) task
Created 2 directories, copied 4 files

Done, without errors.
atilla$ tree pub/
pub/
├── css
│   └── css.css
├── html.html
└── image
    ├── 1.jpg
    └── 2.png

2 directories, 4 files    
Community
  • 1
  • 1
Atilla Ozgur
  • 14,339
  • 3
  • 49
  • 69
  • 5
    great to know you have to wrap your excluding dir with **. This worked for me: `src: ['**/*', '!**/bower_components/**', '!**/node_modules/**', '!gitignore', '!.jshintrc', '!*.json']` – Mattijs Nov 14 '14 at 02:32
  • addition `'!*.txt','!*.md'` also. – vanduc1102 Apr 21 '15 at 04:21
  • 1
    Thanks for the answer-- what I'm seeing, though, is that it's creating the folder on the dest, but just not filling it with files. It's a trivial artifact I can ignore if I need to, but it does bother me a little! Any pointers? – Greg Pettit Jul 23 '15 at 16:48
  • Thanks for this :) The option `!**/directory/goes/here` is not mentioned on the tasks page – Jonathan Cardoz Mar 19 '17 at 19:44