How to list out all the files in the public/images

2019-04-09 07:42发布

I want to list out all the file names in the public/images directory for my Scala Play Framework 2 application so that the Play Application just lists those file names to the HTML page. How can this be done?

Is there a right way to access the public/images directory to read files or list the directory? I don't want to use absolute directory paths.

1条回答
smile是对你的礼貌
2楼-- · 2019-04-09 08:24

There is method getFile(relateivePath: String): File on Play object and also in the Application class which returns file relative to application root directory. In your case:

Play.getFile("public/images")

return File object, which represent public/images/directory. You can call list or listFiles on it to get contents of the directory.

查看更多
登录 后发表回答