0

[edit: solved, see answer below]

I would like to run a task that will copy everything from one directory (a source directory) to another location (a distribution directory) with the exception of one folder. In other words, given the structure:

src
 丨- images
     丨- favicons/
         丨- files.jpg
     丨- other folders/
     丨- individual_file.png

I would like to move "images" but without the "favicons", producing the following:

dist
 丨- images
     丨- other folders/
     丨- individual_file.png

However, what I am getting is this:

dist
 丨- images
     丨- favicons (empty)
     丨- other folders/
     丨- individual_file.png

I have looked at the following questions on SO:

grunt (minimatch/glob) folder exclusion

grunt-contrib-copy - ignore folder when copying

Configure grunt copy task to exclude files/folders

But I am getting something wrong with my syntax. I have used various globbing patterns and the closest success I've had (which works with any number of different globbing patterns) is to create the folder at the destination but without any of the files in it.

Here is what I THINK is more or less the same as the accepted answer in this answer:

imageDist: {
  expand: true,
  cwd: 'src/images/',
  src: ['**/*', '!**/favicons/**'],
  dest: 'dist/images/'
}

But it results in an empty "favicons" directory.

Here's at least one more of the many patterns I tried which also results in an empty "favicons" directory. This one makes the most sense to me because I'm saying "copy everything" and then "except favicons". I don't reaaaalllly need globbing for the exclude match, because I KNOW I have a directory called favicons. I have also tried combinations of leading and trailing slashes (without wildcard) on the following:

imageDist: {
  expand: true,
  cwd: 'src/images/',
  src: ['*', '!favicons'],
  dest: 'dist/images/'
}
Community
  • 1
  • 1
Greg Pettit
  • 10,749
  • 5
  • 53
  • 72
  • I suppose I could always make an "everything else" folder for my general images, but somehow that strikes me as hacking my build rather than having it work as expected. – Greg Pettit Jul 23 '15 at 17:39
  • ...and actually works even worse. It's not pruning the empty folders there, either. – Greg Pettit Jul 23 '15 at 17:48

1 Answers1

0

I don't get it. I noticed that I was also copying my CVS folder, and that during prototyping I wasn't using my template...so I added the CVS exclusion and the template part. This was just in anticipation of someone else knowing a tip for me. As if by magic, the favicon folder also started getting excluded. The working one is pretty much the same as that suggested one:

imageDist: {
  expand: true,
  cwd: 'src/images/',
  src: ['**/*', '!**/CVS/**', '!**/favicons/**'],
  dest: '<%= dirs.dist %>/images/'
}

I reverted back to the plain one from my original question, to check sanity:

imageDist: {
  expand: true,
  cwd: 'src/images/',
  src: ['**/*', '!**/favicons/**'],
  dest: 'dist/images/'
}

... and it seems to work, too.

I can only imagine I had a typo. I mean, I copied and pasted from my Gruntfile (where I tested failure) directly into my question. But somehow... somehow... there must have been a typo that's no longer there.

I'm going to keep this question/answer in here for posterity, but yeah. It seems to work OK now.

Greg Pettit
  • 10,749
  • 5
  • 53
  • 72
  • 1
    I was just about to add a comment stating that the `!**/favicons/**` approach works perfectly for me ;-) – hzpz Jul 23 '15 at 18:12