Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

import (
    "bufio"
    "fmt"
    "os"
)
fileInfo, err := os.Stat("manipulate-filesystem-in-golang.ipynb")
fileInfo
&{manipulate-filesystem-in-golang.ipynb 5209 436 {688987354 63793284779 0x219c440} {2050 38010897 1 33204 1000 1000 0 0 5209 4096 16 {1657639454 51336028} {1657687979 688987354} {1657687979 688987354} [0 0 0]}}
fileInfo.Mode()
-rw-rw-r--
os.Chmod("test.txt", 0777)
fileInfo, err := os.Stat("test.txt")
fileInfo
&{test.txt 0 511 {613146344 63793284812 0x219c440} {2050 38010904 1 33279 1000 1000 0 0 0 4096 0 {1657688012 741146953} {1657688012 613146344} {1657688218 54021852} [0 0 0]}}
fileInfo.Mode()
-rwxrwxrwx
os.Chmod("test.txt", 0664)
fileInfo, err := os.Stat("test.txt")
fileInfo
&{test.txt 0 436 {613146344 63793284812 0x219c440} {2050 38010904 1 33204 1000 1000 0 0 0 4096 0 {1657688012 741146953} {1657688012 613146344} {1657688251 198147320} [0 0 0]}}
fileInfo.Mode()
-rw-rw-r--
os.Create
os.Write

Copy File

The GoLang standard library does not provide a function to copy files directly. However, you can copy a file using ioutil.ReadFile + ioutil.WriteFile.

(*File).WriteString

WriteString is like Write, but writes the contents of string s rather than a slice of bytes.