Golang:如何使用Golang检查Windows上的文件是否为快捷方式文件?

huangapple go评论76阅读模式
英文:

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

问题

我知道如何在Linux上检查文件是否为符号链接文件,例如:

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

但是,在使用Golang时,如何检查文件是否为Windows上的快捷方式文件呢?谁可以帮助我,谢谢。

英文:

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.

答案1

得分: 1

Windows快捷方式文件应该具有扩展名.lnk
你可以通过检查这个来开始。

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

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"
}

huangapple
  • 本文由 发表于 2022年11月22日 17:41:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/74530449.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定