class PhotoController {
def index = {
def baseFolder = grailsAttributes.getApplicationContext().getResource("/").getFile().toString()
def imagesFolder = baseFolder + '/images/sps'
def imageList1 = new File(imagesFolder).list()
[imageList:imageList1]
}
}
以上列出了非jpg文件。我怎么能避免这种情况?!
答案 0 :(得分:5)
您可以在文件夹中调用eachFileMatch方法:
def imageList1 = []
new File(imagesFolder).eachFileMatch(~/.*?\.jpg/) { imageList1 << it }