10

We are using TeamCity to produce *.nupkg artifacts which we don't want to be cleaned up. TeamCity provides a field where you can specify an ANT-style pattern for indicating which files you do or don't want to be cleaned up. Let's assume for a second that we have the following files which we do not want to be cleaned up:

/a.nupkg
/dir1/b.nupkg
/dir1/dir2/c.nupkg

Does the *.nupkg pattern match .nupkg files both in the root directory AND all child directories or do need to use **.*nupkg to traverse all directories?

I read the following documentation but this is still ambiguous to me: http://ant.apache.org/manual/dirtasks.html#patterns

If there is an Ant-Pattern tester (similar to http://regexpal.com/) that would be amazing.

AlBlue
  • 20,872
  • 14
  • 63
  • 85
jakejgordon
  • 3,778
  • 6
  • 31
  • 43
  • Funny, I read the same article and was confused exactly the way you were. I agree, that article was not clear on the meaning/purpose/use of asterisk. – IqbalHamid Jun 28 '18 at 09:58

2 Answers2

6

To match all files, in all directories (from the base directory and deeper)

**/*.nupkg

Will match

sample.nupkg
sample-2.nupkg
tmp/sample.nupkg
tmp/other.nupkg
other/new/sample.nupkg

** will match any directory (multiple directories deep).

*.nupkg will match any file with the nupkg extension. Or just * will match any file or any directory (but just a single directory deep).

PS: There is no Ant Pattern Tester.

Verhagen
  • 3,673
  • 23
  • 35
  • Your answer adds little value as we were already aware that * is a wildcard. You have failed to explain the difference between the use of double asterisk versus single asterisk. This being the point of confusion. – IqbalHamid Jun 28 '18 at 10:01
  • Is there a way to match all files, in all directories except one ? Like for example one that contains string "foo". – mirzak Jan 12 '21 at 14:46
  • @mirzak Mostly there is `` part as well as a `` part. Fill the `foo` in under the exclude part, of the Ant fileset. – Verhagen Jan 14 '21 at 09:08
0

For testing of your patterns a simple way is to echo your fileset contents to stdout or to file, f.e. :

<project>
  <fileset dir="..." id="foobar">
   <include name="..."/>
   <!-- .. -->
  </fileset>

  <!-- simple echo -->
  <echo>${toString:foobar}</echo>

  <!-- use pathconvert for listing files line by line -->
  <pathconvert property="foo" pathsep="${line.separator}" refid="foobar"/>

  <!-- simple echo -->
  <echo>${foo}</echo>

  <!-- print to file -->
  <echo file="whatever.txt">${foo}</echo>

  <!-- use nested mapper if you need only basename -->
  <pathconvert property="fooflat" pathsep="${line.separator}" refid="foobar">
   <mapper>
    <flattenmapper />
   </mapper>
  </pathconvert>

  <echo>$${fooflat} => ${line.separator}${fooflat}</echo>

  <!-- to combine several filesets use -->
  <path id="fooo">
   <fileset dir="...">
    <include name=".."/>
   </fileset>
   <fileset>
     <!-- ... -->
   </fileset>
   <fileset>
     <!-- ... -->
   </fileset>
    <!-- ... -- >
  </path>

  <echo>$${fooo} => ${fooo}</echo>

</project>
Rebse
  • 10,054
  • 2
  • 29
  • 62
  • While your comment is useful, it fails to answer the question. Your response does not explain the difference between * and ** as asked in the question. – IqbalHamid Jun 28 '18 at 10:03
  • @IqbalHamid Seems you didn't read the posting carefully enough. My answer is related to his last question = "If there is an Ant-Pattern tester (similar to regexpal.com) that would be amazing." - so your downvote ain't right – Rebse Jun 29 '18 at 18:30