Akhil Sharma has Published 671 Articles

Golang program to get the name of the file from the absolute path

Akhil Sharma

Akhil Sharma

Updated on 22-Feb-2023 14:49:18

7K+ Views

We are going to use the filepath and string functions of golang to get the file name from the absolute path. An absolute directory begins with the root directory and includes all intermediate directories. In the first method, we will use filepath package functions and in the second example, we ... Read More

Golang program to create directories

Akhil Sharma

Akhil Sharma

Updated on 22-Feb-2023 14:48:16

2K+ Views

Golang has internal packages like os and io packages for creating a new directory. Here, we will create a directory using two examples. In the first example we will use os.Mkdir function and in the second example we will use ioutil.WriteFile function to execute the program. Method 1: Using os.Mkdir ... Read More

Golang program to delete empty and non-empty directory

Akhil Sharma

Akhil Sharma

Updated on 22-Feb-2023 14:47:05

1K+ Views

In golang, we can use os and dir packages to delete a given directory. Here we are using two examples to demonstrate to deletion of an empty and non-empty directory using os.open, os.Removeall. Syntax os.Open This function is a part of os package. It is used to open a ... Read More

Golang program to rename a file

Akhil Sharma

Akhil Sharma

Updated on 22-Feb-2023 14:44:50

426 Views

In golang we can use internal function of OS package to rename a file in various ways. In this article we are going to demonstrate how to change a file name using os. create, os.rename and os.open functions. Method1: Using os.Rename Function In this example, the file oldname.txt is renamed ... Read More

Golang program to delete a file

Akhil Sharma

Akhil Sharma

Updated on 22-Feb-2023 14:42:41

3K+ Views

Golang has os package that is used for deleting a file. In this os package the filename that we wish to delete is initially specified. The file is then deleted using the os.Remove method from the os package.In this article we are using two example to demonstrate the process of ... Read More

Golang program to copy one file into another file

Akhil Sharma

Akhil Sharma

Updated on 22-Feb-2023 14:40:05

2K+ Views

In Golang, we can use Os Packages and IO packages to copy data from one file to another file. n the first method, we'll use OS packages like os.open, os.create and os.copy function. Whereas in the second method, we will use ioutill.Readfile and ioutil.Writefile to copy the files. Method1: ... Read More

Golang Program to rename a specified file by another name

Akhil Sharma

Akhil Sharma

Updated on 22-Feb-2023 14:35:53

1K+ Views

Rename() is one of the internal function of golang used for renaming a specific file. Here we have used three examples in the first one we are using the Rename() function present in os package while in the second example we are using TempFile() function present in the ioutil ... Read More

Golang Program to check a specified file is exist or not

Akhil Sharma

Akhil Sharma

Updated on 22-Feb-2023 14:34:59

496 Views

In golang, we have internal function like stat(), Open(0 and Readfile() that is used for checking whether a specific file exist or not. In the first example we are using the stat() method present in the os package while in the second and third example we are using Open() ... Read More

Golang Program to check a file has writable permission or not

Akhil Sharma

Akhil Sharma

Updated on 22-Feb-2023 14:33:43

2K+ Views

In Golang, we can use openfile() and Stat() function to check whehter a file has writable permission or not. Here we have written two examples. in the first one we are using OpenFile() method present in the os package while in the second one we are using the Stat() method ... Read More

Golang Program to check a directory is exist or not

Akhil Sharma

Akhil Sharma

Updated on 22-Feb-2023 14:27:40

5K+ Views

In golang we have different inbuild function like Stat(), Open() and mkdir() to check whether a directory exist or not . Here we are using three functions. in the first one we are using the Stat() function present in the os package while in the second and third ... Read More

Advertisements