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.3k Golang : Set up source IP address before making HTTP request
+14.4k Golang : Save(pipe) HTTP response into a file
+14.5k Golang : package is not in GOROOT during compilation
+5k Unix/Linux : How to archive and compress entire directory ?
+7.8k Golang : Number guessing game with user input verification example
+5.1k PHP : Convert CSV to JSON with YQL example
+16.5k Golang : Capture stdout of a child process and act according to the result
+11.6k Golang : Perform sanity checks on filename example
+14k Golang : How to check if your program is running in a terminal
+9.6k Golang : Find and replace data in all files recursively
+7.6k Swift : Convert (cast) String to Float