-
-
Save viiftw/4a06eb25084abf586173df0df41ea3ba to your computer and use it in GitHub Desktop.
Revisions
-
toddlers created this gist
Jan 25, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,44 @@ package main import ( "fmt" "os" ) func main() { // can handle symbolic link, but will no follow the link fileInfo, err := os.Lstat("file.txt") // cannot handle symbolic link //fileInfo, err := os.Lstat("file.txt") if err != nil { panic(err) } fmt.Println("Name : ", fileInfo.Name()) fmt.Println("Size : ", fileInfo.Size()) fmt.Println("Mode/permission : ", fileInfo.Mode()) // --- check if file is a symlink if fileInfo.Mode()&os.ModeSymlink == os.ModeSymlink { fmt.Println("File is a symbolic link") } fmt.Println("Modification Time : ", fileInfo.ModTime()) fmt.Println("Is a directory? : ", fileInfo.IsDir()) fmt.Println("Is a regular file? : ", fileInfo.Mode().IsRegular()) fmt.Println("Unix permission bits? : ", fileInfo.Mode().Perm()) fmt.Println("Permission in string : ", fileInfo.Mode().String()) fmt.Println("What else underneath? : ", fileInfo.Sys()) }