'Grrovy how to get directory files by name only without the path I have the following code I need to get the numbers only
Grrovy how to get directory files by name only without the path I have the following code I need to get the numbers only
'''
import groovy.io.FileType
def cnode= []
def dir = new File("/var/jenkins_home/files/")
dir.eachFileRecurse (FileType.FILES) { file ->
cnode << file
}
cnode.each {
cnode = it
println cnode
}
'''
Solution 1:[1]
Thanks to @siking's comment: I added .name, and I got the name instead of the path.
1
2
3
4
5
Result: [1, 2, 3, 4, 5]
'''
import groovy.io.FileType
def cnode = []
def dir = new File("/var/jenkins_home/files/")
dir.eachFileRecurse (FileType.FILES) { file -> cnode << file.name }
cnode.each {
cnode = it
println cnode
}
'''
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jeremy Caney |
