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 Golang : Struct field tags and what is their purpose?
+15.3k nginx: [emerg] unknown directive "ssl"
+15.2k Golang : Save(pipe) HTTP response into a file
+7.7k Gogland : Where to put source code files in package directory for rookie
+12.6k Golang : flag provided but not defined error
+24k Golang : Fix type interface{} has no field or no methods and type assertions example
+7.2k Golang : Null and nil value
+22.2k Golang : Repeat a character by multiple of x factor
+9.7k PHP : Get coordinates latitude/longitude from string
+16.1k Golang : Generate universally unique identifier(UUID) example
+6.5k Golang : Calculate diameter, circumference, area, sphere surface and volume
+15.4k Golang : Get all local users and print out their home directory, description and group id