Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Haskell, how can get the filename without the file extension?

Tags:

haskell

Say I have a filename (a list of characters):

"myfile.xml"

How can I get:

"myfile"

?

like image 821
Jonathan Avatar asked Sep 16 '17 21:09

Jonathan


1 Answers

In case you want to eliminate the extension, I propose to use a library like System.FilePath.Posix:

import System.FilePath.Posix(takeBaseName)

Then you can use the takeBaseName function to obtain the basename of a filename:

Prelude> import System.FilePath.Posix(takeBaseName)
Prelude System.FilePath.Posix> takeBaseName "myfile.xml"
"myfile"

This solution works better, since it will also work on "file.gz" and "foo.7z".

like image 71
Willem Van Onsem Avatar answered Sep 18 '22 22:09

Willem Van Onsem