Does groovy have an easy way to get a filename without the extension?

file-extension, file-io, groovy, java

Solution

I believe the grooviest way would be:

file.name.lastIndexOf('.').with {it != -1 ? file.name[0..<it] : file.name}

or with a simple regexp:

file.name.replaceFirst(~/\.[^\.]+$/, '')

also there's an apache commons-io java lib for that kinda purposes, which you could easily depend on if you use maven:

org.apache.commons.io.FilenameUtils.getBaseName(file.name)

Problem

Say I have something like this: ``` new File("test").eachFile() { file-> println file.getName() } ``` This prints the full filename of every file in the `test` directory. Is there a Groovy way to get the filename without any extension? (Or am I back in regex land?)

Original source