Created
April 4, 2013 17:03
-
-
Save yangkun/5312119 to your computer and use it in GitHub Desktop.
[groovy] list dirs/files (dir first and sort as name)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import groovy.io.* | |
def listfiles(dir) { | |
dlist = [] | |
flist = [] | |
new File(dir).eachDir {dlist << it.name } | |
dlist.sort() | |
new File(dir).eachFile(FileType.FILES, {flist << it.name }) | |
flist.sort() | |
return (dlist << flist).flatten() | |
} | |
fs = listfiles(".") | |
fs.each { | |
println it | |
} |
Well, I figured it out, and I was running it on a Linux machine.
Thanks, @herculosh for a Quick reply :)
Below is my code, Hopefully, it will useful for someone, I am running this code as a groovy script in Jenkins Pipeline
**@NonCPS
def fetFilenamesFromDir(def dir, def list){
dir.eachFileRecurse (FileType.FILES) { file ->
file = file.toString()
if (file.endsWith("json")){
list << file
}
}
}
node('master'){
def list = []
def dir = new File("dirPathToBeDefined")
fetFilenamesFromDir(dir,list)
for (i in list){
print i
print("\n")
}**
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So if I understand you correctly you want to use the script in the Jenkins pipeline. I haven't tried that yet, but I know that a loop and then more calls from sh-instructions in the scripted-pipeline have to be converted to functions and have to be marked as such.
I am using the script in connection with "Active Choises Reactive Parameter". Works very well under Windows. On Mac OSX, I'm having permissions issues since the upgrade to Catalina.
What do you get for an error in the console log?