I believe common convention is to include the dot.
-joe
After reading the documentation I hope you now expect the dot too.
I bet this isn't the first thing about Go that was different than what
you expected.
Including the dot in the return value allows path.Ext to distinguish
between the inputs "foo." and "foo".
Russ
I wouldn't consider wikipedia as the normative source.
Informative yes, but not normative.
But even if you ignore the documentation's function description,
it is consistent with that function, but I guess it depends on
what you're expecting based on the language/s you've used.
Eg, the Python and Ruby built-in functions include the dot whereas
(I can see that) PHP and C# don't.
-joe
python
---------
>> import os
>> file = "/this/file/extension/contains/a/dot/file.here"
>> ext = os.path.splitext(file)[1]
>> print ext
output> .here
ruby
------
file = "/this/file/extension/contains/a/dot/file.here"
ext = File.extname(file)
puts ext
output> .here
php
-----
$file = "/this/file/extension/has/no/dot/file.nodot"
$ext = pathinfo($file, PATHINFO_EXTENSION)
echo $ext
output> nodot
C#
----
string file = "/this/file/extension/has/no/dot/file.nodot"
string ext = Path.GetExtension(file)
System.Console.WriteLine(ext)
output> nodot
The file extension in your example /does/ have an empty string after the
delimiter. Remember that some languages include the dot with the returned
extension and some don't, Go does.
ext := path.Ext("file.")
if ext != "" {
// not empty therefore at least the dot delimiter exists
if ext[1:] == "" {
fmt.Println("ext is an empty string")
} else {
fmt.Println("ext is ", ext[1:])
}
} else {
fmt.Println("the file has no extension")
}
-joe
Sounds like MS-DOS to me.
Other systems distinguish 'base.' from 'base',
and path.Ext does too.
Russ