Golang : Delete file
Deleting file in Go is simple. This short tutorial will demonstrate how to delete a file.
Let choose a file deleteme.file
as target practice and the code example below will remove the deleteme.file
when executed.
deletefile.go
package main
import (
"fmt"
"os"
)
func main() {
err := os.Remove("deleteme.file")
if err != nil {
fmt.Println(err)
return
}
}
Reference :
See also : Golang : Rename file
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+6.3k Golang : File system scanning
+50.1k Golang : Check if item is in slice/array
+19.6k Golang : Create and resolve(read) symbolic links
+5.1k Golang : Dealing with backquote
+4.9k Golang : How to search a list of records or data structures
+11.4k Golang : HTTP response JSON encoded data
+11.2k Golang : How to check if a string starts or ends with certain characters or words?
+19.2k PHP : Convert(cast) int to double/float
+6.4k Golang : Individual and total number of words counter example
+35.6k Upload multiple files with Go
+10.8k Golang : Save webcamera frames to video file
+16.4k Golang : How to log each HTTP request to your web server?