开发者

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 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜