get file name without extension

2,007 views
Skip to first unread message

Tong Sun

unread,
Nov 9, 2015, 5:12:00 PM11/9/15
to golang-nuts

How to get file name without extension? 

I thought this is so fundamental that it should be provided out of box, but didn't find in https://golang.org/pkg/path/ or https://golang.org/pkg/path/filepath/

Is it not provided by default or I was looking in the wrong places? 

Thanks

Shawn Milochik

unread,
Nov 9, 2015, 5:14:17 PM11/9/15
to golang-nuts
You can use Ext() to get the extension:

Then it's easy enough to chop the len of those characters off of the end of the original path. 

Michael Jones

unread,
Nov 9, 2015, 5:34:39 PM11/9/15
to Sh...@milochik.com, golang-nuts
Do this: http://play.golang.org/p/1IKvsWHTGy

— 
Michael Jones, CEO  •  mic...@wearality.com  •  +1 650 656-6989 
Wearality Corporation  •  289 S. San Antonio Road  •  Los Altos, CA 94022

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Jones

unread,
Nov 9, 2015, 5:35:40 PM11/9/15
to Sh...@milochik.com, golang-nuts


— 
Michael Jones, CEO  •  mic...@wearality.com  •  +1 650 656-6989 
Wearality Corporation  •  289 S. San Antonio Road  •  Los Altos, CA 94022

Tong Sun

unread,
Nov 9, 2015, 5:36:35 PM11/9/15
to Michael Jones, Sh...@milochik.com, golang-nuts
Ah, much better. Thanks. 

--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/FqUL7WZpM7w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.

Giulio Iotti

unread,
Nov 10, 2015, 2:18:47 AM11/10/15
to golang-nuts, Sh...@milochik.com
On Monday, November 9, 2015 at 11:35:40 PM UTC+1, Michael Jones wrote:

Typo only if you consider a hidden filename an extension.

Isn't the previous version better?

-- 
Giulio Iotti

Matt Harden

unread,
Nov 10, 2015, 5:38:30 PM11/10/15
to Giulio Iotti, golang-nuts, Sh...@milochik.com
That's just a UNIX convention. path.Ext acts the same way.

--
Reply all
Reply to author
Forward
0 new messages