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
+16.2k Golang : Delete files by extension
+4.8k Linux/Unix/MacOSX : Find out which application is listening to port 80 or use which IP version
+28.9k Golang : Saving(serializing) and reading file with GOB
+27.7k Golang : Move file to another directory
+4.8k Golang : Get a list of crosses(instruments) available to trade from Oanda account
+21.9k Golang : Repeat a character by multiple of x factor
+14.8k JavaScript/JQuery : Detect or intercept enter key pressed example
+5.4k Golang : Configure crontab to poll every two minutes 8am to 6pm Monday to Friday
+18.4k Golang : convert int to string
+7.1k Golang : How to convert strange string to JSON with json.MarshalIndent
+40.7k Golang : How to check if a string contains another sub-string?
+15.8k Golang : Get sub string example