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
+5.7k CodeIgniter/PHP : Remove empty lines above RSS or ATOM xml tag
+14.3k Golang : How to shuffle elements in array or slice?
+18.9k Golang : Read input from console line
+14.7k Golang : Normalize unicode strings for comparison purpose
+44.8k Golang : Use wildcard patterns with filepath.Glob() example
+16.7k Golang : Read integer from file into array
+14.1k Golang : Check if a file exist or not
+16.9k Golang : Fix cannot convert buffer (type *bytes.Buffer) to type string error
+18.4k Golang : Logging with logrus
+11.3k Golang : Delay or limit HTTP requests example
+11.1k Google Maps URL parameters configuration
+12.4k Golang : "https://" not allowed in import path