To find the name of a file in Go, we can use the path/filepath package which provides various utilities for working with file paths.
We can use the Base function from this package which will return the last element of the path or the file name alone.
Here's an example code snippet:
main.go254 chars17 linesIn the above code, we have provided a file path and used the filepath.Base function to get the file name. The fmt package is used to print the file name to the console.
Output:
main.go20 chars2 lines
gistlibby LogSnag