awesome-go/impl/files-manipulation/09-ChangeFilePermissions.go

37 lines
702 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"log"
"os"
"time"
)
func main() {
/*
İzinleri, Sahipliği ve Zaman Damgalarını(Timestamps) Değiştirmek Change Permissions, Ownership, and Timestamps
*/
// İzinleri değiştirme (Linux tarzı)
err := os.Chmod("demo.txt", 0777)
if err != nil {
log.Println(err)
}
// Sahipliği değiştirme
err = os.Chown("demo.txt", os.Getuid(), os.Getgid())
if err != nil {
log.Println(err)
}
// Zaman Damgalarını(Timestamps) Değiştirme
twoDaysFromNow := time.Now().Add(48 * time.Hour)
lastAccessTime := twoDaysFromNow
lastModifyTime := twoDaysFromNow
err = os.Chtimes("demo.txt", lastAccessTime, lastModifyTime)
if err != nil {
log.Println(err)
}
}