You can use the path/filepath
package in Go to find the path of a file. Here's a simple example:
main.go218 chars16 lines
In this example, we're using the filepath.Abs
function to get the absolute path of the file "path/to/file.txt". If there's an error, we print it to the console. Otherwise, we print the path to the console.
Note that the filepath
package is designed to work with paths in a way that is consistent across different operating systems.
gistlibby LogSnag