how to read only images from a folder?
class PhotoController {
def index = {
def baseFolder = grailsAttributes.getApplicationContext().getResource("/").getFile().toString()
开发者_StackOverflow def imagesFolder = baseFolder + '/images/sps'
def imageList1 = new File(imagesFolder).list()
[imageList:imageList1]
}
}
The above is listing non-jpg files too. How can I avoid that?!
You can invoke the eachFileMatch method on the folder:
def imageList1 = []
new File(imagesFolder).eachFileMatch(~/.*?\.jpg/) { imageList1 << it }
精彩评论