newbie: IsSymlink

4,382 views
Skip to first unread message

TK

unread,
May 6, 2012, 12:19:15 PM5/6/12
to golang-nuts
Hi,

to which package or type belonged the function IsSymlink (it will
return from os.Stat() earlier)?

Thanks for help.

o-o

Thomas

Dmitry Chestnykh

unread,
May 6, 2012, 12:36:33 PM5/6/12
to golan...@googlegroups.com
Do learn if a file is a symlink, do Lstat() on it, then check its mode:
      
        fi, err := os.Lstat(filename)
        // ..check err...
if fi.Mode() & os.ModeSymlink == os.ModeSymlink {
// This is a symlink
} else {
// Not a symlink

Thomas Kaufmann

unread,
May 6, 2012, 12:38:37 PM5/6/12
to golan...@googlegroups.com
THanx a lot!!!

Thomas Kaufmann

unread,
May 6, 2012, 12:55:40 PM5/6/12
to golan...@googlegroups.com
And what about with fi.IsRegular?

Brad Fitzpatrick

unread,
May 6, 2012, 5:43:13 PM5/6/12
to Thomas Kaufmann, golan...@googlegroups.com
From the docs on package os:

"
    // Mask for the type bits. For regular files, none will be set.
    ModeType = ModeDir | ModeSymlink | ModeNamedPipe | ModeSocket | ModeDevice

Thomas Kaufmann

unread,
May 7, 2012, 4:16:54 PM5/7/12
to golan...@googlegroups.com

Thomas Kaufmann

unread,
May 7, 2012, 4:19:52 PM5/7/12
to golan...@googlegroups.com, Thomas Kaufmann
Thanx. But I don't understand this code;-).

Thomas Kaufmann

unread,
May 7, 2012, 4:21:55 PM5/7/12
to golan...@googlegroups.com

Devon H. O'Dell

unread,
May 7, 2012, 4:27:43 PM5/7/12
to Thomas Kaufmann, golan...@googlegroups.com
2012/5/7 Thomas Kaufmann <tok...@googlemail.com>:
> Thanx. But I don't understand this code;-).

It means that iff ModeType == 0, it is a regular file. I suggest
reading documentation.

Please fix your mail client.

--dho

Thomas Kaufmann

unread,
May 7, 2012, 4:50:39 PM5/7/12
to golan...@googlegroups.com, Thomas Kaufmann
Thank you.
Reply all
Reply to author
Forward
0 new messages