Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
27
Task/File-modification-time/Go/file-modification-time.go
Normal file
27
Task/File-modification-time/Go/file-modification-time.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
var filename = "input.txt"
|
||||
|
||||
func main() {
|
||||
foo, err := os.Stat(filename)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("mod time was:", foo.ModTime())
|
||||
mtime := time.Now()
|
||||
atime := mtime // a default, because os.Chtimes has an atime parameter.
|
||||
// but see if there's a real atime that we can preserve.
|
||||
if ss, ok := foo.Sys().(*syscall.Stat_t); ok {
|
||||
atime = time.Unix(ss.Atim.Sec, ss.Atim.Nsec)
|
||||
}
|
||||
os.Chtimes(filename, atime, mtime)
|
||||
fmt.Println("mod time now:", mtime)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue