• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

OCPJP global search

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody,

I am preparing myself for OCPJP exam and i am a little confused about that global **/*.txt .
I know ** means to search for zero or more directories
*.txt means to search for zero or more characters followed by txt without including any directories.

So **/*.txt means to search for zero or more directories followed by slash followed by zero or more characters followed by txt.

Now what i do not understand why the usage of slash makes compiler to search one or more directories?

In such that case it means i can not search using DirectoryStream since it search to only immediate files in the directory.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

johnsoan smith wrote:I am preparing myself for OCPJP exam and i am a little confused about that global **/*.txt .


I assume you are referring to the glob syntax.

johnsoan smith wrote:I know ** means to search for zero or more directories
*.txt means to search for zero or more characters followed by txt without including any directories.


You are correct! One asterisk means "match any character, except for a directory boundary" and two asterisks means "match any character, including a directory boundary".

johnsoan smith wrote:So **/*.txt means to search for zero or more directories followed by slash followed by zero or more characters followed by txt.


Indeed! Using **/*.txt you'll be searching for all text files in any (sub)directory.

Now what i do not understand why the usage of slash makes compiler to search one or more directories?


I don't understand your question. First of all, the compiler only compiles your code, so it definitely doesn't search for one or more directories. Secondly two asterisks means "match any character, including a directory boundary", that's why the JVM searches in one or more directories. A small illustrative code snippetWhen you execute this code snippet, the output will be "true true true false ".

If you wanted for example to search for all text files in any subdirectory "password", you would use the following glob pattern: "**/password/**.txt".

Hope it helps!
Kind regards,
Roel
 
reply
    Bookmark Topic Watch Topic
  • New Topic