How to Delete or Remove a File in Golang? Last Updated : 02 Apr, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report In the Go language, you are allowed to remove the existing file with the help of the Remove() method. This method removes the specified file from the director or it also removes empty directories. If the given path is incorrect, then it will throw an error of type *PathError. It is defined under the os package so, you have to import os package in your program for accessing Remove() function. Syntax: func Remove(file_name string) error Example 1: C // Golang program to illustrate how to // remove files from the default directory package main import ( "log" "os" ) func main() { // Removing file from the directory // Using Remove() function e := os.Remove("GeeksforGeeks.txt") if e != nil { log.Fatal(e) } } Output: Before: After: Example 2: C // Golang program to illustrate how to remove // files from the specified directory package main import ( "log" "os" ) func main() { // Removing file // Using Remove() function e := os.Remove("/Users/anki/Documents/new_folder/GeeksforGeeks.txt") if e != nil { log.Fatal(e) } } Output: Before: After: Comment More infoAdvertise with us Next Article How to Rename and Move a File in Golang? A ankita_saini Follow Improve Article Tags : Go Language Golang-File-Handling Similar Reads How to Rename and Move a File in Golang? In the Go language, you are allowed to rename and move the existing file to a new path with the help of the Rename() method. This method is used to rename and move a file from the old path to the new path. If the given new path already exists and it is not in a directory, then this method will repla 2 min read How to Read a CSV File in Golang? Golang offers a vast inbuilt library that can be used to perform read and write operations on files. To read a CSV file, the following methods are used in Golang: os.Open(): The os.Open() method opens the named file for reading. This method returns either the os.File pointer or an error. encoding/cs 4 min read How to Create an Empty File in Golang? Like other programming languages, Go language also allows you to create files. For creating a file it provides Create() function, this function is used to create or truncates the given named file. This method will truncate the file, if the given file is already exists. This method will create a file 2 min read How to Read and Write the Files in Golang? Golang offers a vast inbuilt library that can be used to perform read and write operations on files. In order to read from files on the local system, the io/ioutil module is put to use. The io/ioutil module is also used to write content to the file. This revised version reflects the changes made in 4 min read How to Create Modules in Golang? Go has included support for versioned modules as proposed here since 1.11 with the initial prototype as vgo. The concept of modules in Go was introduced to handle the problem of dependencies within your Go applications. Several packages are collected and combined to form a module which is stored in 3 min read How to Uncompress a File in Golang? As per Wikipedia, data compression or file compression can be understood as a process of reducing the size of a particular file/folder/whatever data while still preserving the original data. Lesser file size has a lot of benefits as it will then occupy lesser storage area giving you more space for o 6 min read Like