Cookies management by TermsFeed Cookie Consent
Russia has invaded Ukraine and already killed tens of thousands of civilians, with many more raped or tortured. It's a genocide. We need your help. Let's fight back against the Russian regime.
Help Ukraine! Fight the Russian regime!

๐Ÿงน Delete or remove a file in Go

shorts introduction file

Please consider supporting us by disabling your ad blocker

To delete/remove a file in Go, use the built-in os.Remove() function:

package main

import (
    "log"
    "os"
)

func main() {
    if err := os.Remove("testfile.txt"); err != nil {
        log.Fatal(err)
    }
}

If the file exists, the function removes the file without any error. If there is some problem, it returns an error of type *os.PathError. For example, if the file does not exist, the error is:

2022/04/05 06:16:05 remove testfile.txt: no such file or directory
exit status 1

๐Ÿค Create a new file in Go

shorts introduction file

๐Ÿ“ Create a directory in Go

Learn how to create a single or a hierarchy of directories
introduction file

๐Ÿ“Ž Convert JSON to CSV in Go

Learn how to transform JSON file to CSV
introduction file json csv