Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do i add a wildcard to a file path in groovy?

Tags:

groovy

Im currently writing a spock test and need to add a wild card to a file path. the script should look into the subjects folder and into all the subfolders to find the advanced folder and look for exam.txt, however, i keep receiving an error saying FileNotFound.

I believe the code is correct as it can parse files fine but the wildcard bit throws the exception.

new File("School/Exams/Questions/Subjects/**/Advanced")
 if(it.name.matches("questions.txt"){
   print it
       }
like image 482
user7502743 Avatar asked Feb 05 '23 04:02

user7502743


1 Answers

You can use FileNameFinder to get list of file names:

new FileNameFinder()
    .getFileNames('School/Exams/Questions/Subjects/', '**/Advanced/questions.txt')
like image 162
Michal Kordas Avatar answered Jun 03 '23 19:06

Michal Kordas