1

I have below files:

C:\files\file1.dll
C:\files\file2.dll
C:\files\sample\sample1.dll
c:\files\sample\sample2.dll
c:\files\book\book1.dll
c:\files\book\book2.dll
c:\files\book\comic\comic1.dll
c:\files\book\comic\comic2.dll

pattern 1 is *\*.dll, pattern 2 is *\comic\*.dll and pattern 3 is book\*\*.dll. What files should match pattern1, pattern2 and pattern3

Tân
  • 1
  • 15
  • 56
  • 102
Kalyani Reddy
  • 131
  • 10

1 Answers1

1

The first pattern should match everything in wildcard matching. You are basically saying.

Contains \ and ends with .dll

The second one should match the last two.

Contains \comic\ and ends with .dll

The last one should match nothing.

Starts with book\ contains \ and ends with .dll

This of course is for pattern matching as described here Matching strings with wildcard and not regular expressions.

In the glob world, it's not exactly that:

** matches any character including a forward-slash /

* matches any character except a forward-slash (to match just the file or directory name)

So think about it this way. The first pattern will only match the first and the second. By using the double ** you effectively say, I also care about subdirectories.

excellent explanation with more examples: here

Athanasios Kataras
  • 25,191
  • 4
  • 32
  • 61
  • Thanks for swift reply, but what i thought is * means all files in specified source folder. ** means all files in the specified source folder and all files in all sub-folders as per [copy files task azure](https://learn.microsoft.com/en-us/azure/devops/pipelines/tasks/utility/copy-files?view=azure-devops&tabs=yaml). So by using azure copy task doesn't pattern1 matches - file1.dll, file2.dll,sample1.dll, sample2.dll, book1.dll and book2.dll? Pattern 3 matches - book1.dll, book2.dll, comic1.dll, comic2.dll – Kalyani Reddy Dec 02 '19 at 08:11
  • So you are trying to match using http://man7.org/linux/man-pages/man3/fnmatch.3.html. Ok, now that I know what you are trying to achieve I might help some more. – Athanasios Kataras Dec 02 '19 at 08:16
  • Thanks, understood a little bit. But how C:\files\\*\\*.dll pattern work for above files? – Kalyani Reddy Dec 02 '19 at 08:39
  • It should return the 2nd, 3rd, 4th and 5th rows. Not the first or the last two. – Athanasios Kataras Dec 02 '19 at 08:42
  • Super, And last doubt - c:\files\\**\\*.dll pattern matches all files , but why c:\files\\*\\*.dll pattern does not match 1 to 6 rows but matches only 3 to 6 rows – Kalyani Reddy Dec 02 '19 at 08:50
  • because the double asterisk, contains folders and the single asterisk does not. – Athanasios Kataras Dec 02 '19 at 08:51
  • Thanks for your swift reply, and also i understood the concept – Kalyani Reddy Dec 02 '19 at 08:54