1. 程式人生 > >golang symbolic links

golang symbolic links

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