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
+8.4k Golang : Convert(cast) string to int64
+4k Google : Block or disable caching of your website content
+7.3k Golang : Ackermann function example
+10.5k Golang : Get remaining text such as id or filename after last segment in URL path
+23.7k Golang : Get current file path of a file or executable
+44.3k Golang : Marshal and unmarshal json.RawMessage struct example
+15.3k Golang : Get the IPv4 and IPv6 addresses for a specific network interface
+23.9k Golang : Convert uint value to string type
+14.2k Golang : Delete certain files in a directory
+11.3k Golang : Remove or trim extra comma from CSV
+12.6k Golang : Compress and decompress file with compress/flate example
+15.8k Golang : Get number of CPU cores