To find the extension of a CSV file in Go, you can use the path/filepath
package. Here's an example code that demonstrates how to do this:
main.go302 chars18 lines
In this example, we first use the filepath
package to get the extension of the file by calling filepath.Ext(filename)
. This function returns the extension of the file, including the dot (.
).
We then convert the extension to lowercase using the strings.ToLower()
function, and compare it with the lowercase .csv
string. If they match, we print a message indicating that the file is a CSV file. Otherwise, we print a message indicating that the file is not a CSV file.
gistlibby LogSnag