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
+7.5k Javascript : Read/parse JSON data from HTTP response
+7.2k Golang : Display a text file line by line with line number example
+3.2k Unix/Linux/MacOSx : Get local IP address
+10.3k Golang : Validate hostname
+8.4k Golang : Convert spaces to tabs and back to spaces example
+7.3k Golang : Sort and reverse sort a slice of runes
+3.5k Golang : Display advertisement images or strings on random order
+11.2k Golang : How to check for empty array string or string?
+14.4k Unmarshal/Load CSV record into struct in Go
+4k Golang : Get missing location after unmarshal binary and gob decode time.
+2.8k Golang : Print instead of building pyramids
+5.8k Golang : Ordinal and Ordinalize a given number to the English ordinal numeral