2

Currently the code takes a string containing the directory and exact filename and has a Boolean to test the existence of the file.

String inFilepathAndFileName = "fileDirectory\subFolder\TestFile.txt"
inFilepathAndFileName.exists // returns 0 or 1

I want to expand the functionality to Boolean for a filename with a wildcard, such as:

"TestFile_001.txt"

The input would ideally be:

"fileDirectory\subFolder\TestFile*"

In this scenario, there will never be multiple files fitting this criteria, only 1 or 0.

Using the java.nio. libraries seem to have potential for this functionality but I cannot seem to find an efficient method with my lack of knowledge.

  • You cannot guarantee that "in this scenario, there will never be multiple files fitting this criteria, only 1 or 0", so let's not tie that down. That said, if I google for "java find files with wildcards" I find good answers right here on Stackoverflow, so please remember to take the [tour] and read ["how to ask a good question"](/help/how-to-ask), and make sure to first cover the "search and research" part of the process. – Mike 'Pomax' Kamermans Jan 16 '19 at 04:55
  • 1
    Possible duplicate of [How to find files that match a wildcard string in Java?](https://stackoverflow.com/questions/794381/how-to-find-files-that-match-a-wildcard-string-in-java) – Mike 'Pomax' Kamermans Jan 16 '19 at 04:55
  • Alternatively, [How to check a file if exists with wildcard in Java?](https://stackoverflow.com/questions/8752034/how-to-check-a-file-if-exists-with-wildcard-in-java) – Mike 'Pomax' Kamermans Jan 16 '19 at 04:56

0 Answers0