英文:
How to detect broken symlinks in Go?
问题
我尝试使用ff, _ := os.Open("Filename")
打开文件,然后运行ffi, _ := ff.Stat()
。
这是我能找到的最接近提供任何细节的方法,但似乎没有遵循符号链接。
我真正想做的是从符号链接中提取原始文件名(该文件已被删除)。
我在Linux机器上。
英文:
I have tried opening the file with ff, _ := os.Open("Filename")
and then running ffi, _ := ff.Stat()
.
Which is the closest thing I could find that provides any details, but that doesn't seem to be following the symlinks.
What I'm really trying to do is extract the original file name (which is deleted) from the symlink.
I'm on a Linux machine.
答案1
得分: 3
os.Readlink(filename)
就可以了。
英文:
os.Readlink(filename)
does it.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论