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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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")
}**