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.4k Golang : How to search a list of records or data structures
+7.6k Golang : Create zip/ePub file without compression(use Store algorithm)
+9.5k Golang : Web(Javascript) to server-side websocket example
+9.1k Golang : Get SPF and DMARC from email headers to fight spam
+32.2k Golang : Convert an image file to []byte
+20.4k Golang : Determine if directory is empty with os.File.Readdir() function
+5.3k Golang : The Tao of importing package
+15.4k Golang : Accurate and reliable decimal calculations
+9.2k Golang : Simple histogram example
+15k Golang : Basic authentication with .htpasswd file
+30.5k Golang : How to verify uploaded file is image or allowed file types
+18.6k Golang : Aligning strings to right, left and center with fill example