Issue
Updated! thanks to @ycr
filesArray = []
def listFiles(def path, def filter) {
def filterBakFiles = ~/(?i)${filter}.*\.bak$/
new File(path).traverse(type: groovy.io.FileType.FILES, nameFilter: filterBakFiles) { file ->
filesArray << file.name
}
if (folder && filter && filesArray) {
return filesArray
} else if (!filesArray) {
return ["No coincidences"]
} else {
return ["please enter folder and filter"]
}
}
listFiles("\\\\networkpath\\${folder}", "${filter}")
this works!. now i'm trying to fix the regex for find coincidences with numbers and text.
def filterBakFiles = ~/(?i)${filter}.*\.bak$/
best regards
Solution
Check the following.
@NonCPS
def listFiles(def path) {
def filterBakFiles = ~/.*\.bak$/
new File(path).traverse(type: groovy.io.FileType.FILES, nameFilter: filterBakFiles) { file ->
println file
}
}
Answered By - ycr
Answer Checked By - Mary Flores (JavaFixing Volunteer)