살인!
golang
golang - golang File Access and Create Time 파일 생성 수정 시간, 타임
이 름 : 바다아이
|
조회수 : 8954
짧은 주소 : https://www.bada-ie.com/su/?841591871164
package main
import (
"fmt"
"os"
"syscall"
"time"
)
func statTimes ( name string ) ( atime , mtime , ctime time . Time , err error ) {
fi , err := os . Stat ( name )
if err != nil {
return
}
mtime = fi . ModTime ()
stat := fi . Sys ().(* syscall . Stat_t )
atime = time . Unix ( int64 ( stat . Atim . Sec ), int64 ( stat . Atim . Nsec ))
ctime = time . Unix ( int64 ( stat . Ctim . Sec ), int64 ( stat . Ctim . Nsec ))
return
}
func main () {
name := "파일이름 "
atime , mtime , ctime , err := statTimes ( name )
if err != nil {
fmt . Println ( err )
return
}
fmt . Println ( atime , mtime )
fmt . Println ( ctime )
err = os . Chtimes ( name , atime , mtime )
if err != nil {
fmt . Println ( err )
return
}
atime , mtime , ctime , err = statTimes ( name )
if err != nil {
fmt . Println ( err )
return
}
fmt . Println ( atime , mtime )
fmt . Println ( ctime )
}
출처 : https://stackoverflow.com/questions/20875336/how-can-i-get-a-files-ctime-atime-mtime-and-change-them-using-golang
|
|