Welcome To Golang By Example

Menu
  • Home
  • Blog
Menu

Delete a file in Go (Golang)

Posted on February 23, 2023February 23, 2023 by admin

os.Remove() function can be used to delete a file in Golang. Below is the signature of this function

func Remove(name string) error

Code:

package main
import (
"log"
"os"
)
func main() {
err := os.Remove("sample.txt")
if err != nil {
log.Fatal(err)
}
}

Output:

Deletes sample.txt file from the current working directory
  • delete
  • golang
  • remove
  • Popular Articles

    Golang Comprehensive Tutorial Series

    All Design Patterns in Go (Golang)

    Slice in golang

    Variables in Go (Golang) – Complete Guide

    OOP: Inheritance in GOLANG complete guide

    Using Context Package in GO (Golang) – Complete Guide

    All data types in Golang with examples

    Understanding time and date in Go (Golang) – Complete Guide

    ©2023 Welcome To Golang By Example | Design: Web XP