Search code examples
windowsgoshortcut

Golang: How to check a file whether is a shortcut file on windows using Golang?


I know how to check a file whether is a symbolic link file on linux, such as:

func IsSymLink(path string) bool {
    if info, err := os.Lstat(path); err == nil && info.Mode()&os.ModeSymlink != 0 {
        return true
    }
    return false
}

But, how to check a file whether is a shortcut file on windows uing Golang? who can help me, thx.


Solution

  • Windows shortcut files should have an extension .lnk. You could start by checking for that.

    func IsWinShortcut(path string) bool {
        return filepath.Ext(path) == ".lnk"
    }