Scala - remove jpg from folder

I am looking for an elegant way to delete all files in a folder with a .jpg extension

I have the following to count the common jpg files in a folder:

Option(new File(path).list).map(_.filter(_.endsWith(".jpg")).size).getOrElse(0)


Thanks in advance, any help is greatly appreciated :)


source to share

1 answer

for {
  files <- Option(new File(path).listFiles)
  file <- files if file.getName.endsWith(".jpg")
} file.delete()




All Articles