Created
December 1, 2013 17:08
-
-
Save micahredding/7736838 to your computer and use it in GitHub Desktop.
Go Function to Return MacOS X created time (birthtime)
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 characters
package main | |
import ( | |
"fmt" | |
"log" | |
"os" | |
"syscall" | |
"time" | |
) | |
func GetCreatedTime(file string) (crtime time.Time) { | |
f, err := os.Open(file) | |
defer f.Close() | |
if err != nil { | |
log.Fatal(err) | |
} | |
// More details using the syscall package | |
var s syscall.Stat_t | |
// Get the file descriptor | |
fd := int(f.Fd()) | |
err = syscall.Fstat(fd, &s) | |
if err != nil { | |
log.Fatal(err) | |
} | |
return time.Unix(s.Birthtimespec.Unix()) | |
} | |
func main() { | |
crtime := GetCreatedTime("test.go") | |
fmt.Printf(" birth: %s\n ", crtime) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment