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 snippet
When 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