golang symbolic links
阿新 • • 發佈:2018-01-25
lin amp lena ext mar ase png mark mage
package main import ( "fmt" "os" "path/filepath" ) func main() { arguments := os.Args if len(arguments) == 1 { fmt.Println("Please provide an argument!") os.Exit(1) } filename := arguments[1] fileInfo, err := os.Lstat(filename) if err != nil { fmt.Println(err) os.Exit(1) } if fileInfo.Mode()&os.ModeSymlink != 0 { fmt.Println(filename, "is a symbolic link") realPath, err := filepath.EvalSymlinks(filename) if err == nil { fmt.Println("Path:", realPath) } } }
golang symbolic links