Akhil Sharma

Akhil Sharma

507 Articles Published

Articles by Akhil Sharma

Page 12 of 51

Golang Program to Get the size of a directory

Akhil Sharma
Akhil Sharma
Updated on 03-May-2023 2K+ Views

In golang, it is easy to get the size of file, but getting the size of a directory is a bit complex. Here in this article we will use os.Open() function , walk function as well as readdir() function to get the size of a directory. Syntax funcReadDir(dirname string) ([]fs.FileInfo, error) The ReadDir() function is present in os package and is used to read the directory. The function accepts one argument which is the name of the directory which is to be read and returns a list FileInfo for directory’s content. If an error is generated while reading the ...

Read More

Golang Program to Display all the directories in a directory

Akhil Sharma
Akhil Sharma
Updated on 03-May-2023 216 Views

In this golang article, we will write a go language program to display all the directories in a given directory using the Go programming language using the open() function, using the walk function as well as using the readdir function. Method 1 In this Example we will write a go language program to display all the directories in a directory by using the open() function present in os package. One of the simplest methods to display the directories in a given directory is to use the os.Open() function. Example package main import ( "fmt" ...

Read More

Golang Program to Delete a Directory

Akhil Sharma
Akhil Sharma
Updated on 03-May-2023 296 Views

In this golang article, we will delete a directory in Golang using thhe os.Remove() function as well as using os.RemoveAll() function. There are many inbuilt functions present in go to remove a directory, and we will discuss two of such methods in this program. In computer languages a directory is a container or a file system object that contains information about files and other directories. Syntax funcRemove(file_name string) error The remove function is present in os package and is used to remove a particular file or directory. The function accepts one argument which is the name of the file ...

Read More

Sending Email Using Smtp in Golang

Akhil Sharma
Akhil Sharma
Updated on 03-May-2023 1K+ Views

In this golang article, we can send email using SMTP’s SendMail method, as well as using SMTP with go mail method, SMTP stands for simple mail transfer protocol. This protocol is used to send messages between the servers. The net/smtp package provides a medium to send messages hence it must be imported in the program. Syntax smtp.PlainAuth() This function belongs to the smtp and is primarily used to authenticate with the SMTP server using plain authentication. smtp.SendMail() This function is present in the SMTP package. It is used to send the message from the SMTP server. smtpClient.Auth() ...

Read More

Golang program to implement recursive anonymous function

Akhil Sharma
Akhil Sharma
Updated on 03-May-2023 498 Views

In this Go language article, we will write programs to implement recursive anonymous function by generating fibonacci numbers, by using cache, as well as factorial of a number. An anonymous function is the function which does not have its name and it calls itself within its own body and when repeated calls are made, it called as recursive functions. Method 1 In this Example, we will generate Fibonacci numbers recursively by using an anonymous function. Here, fibo is assigned to the anonymous function with func and an input parameter. Algorithm Step 1 − Create a package main and declare ...

Read More

Overview of Testing Package in Golang

Akhil Sharma
Akhil Sharma
Updated on 03-May-2023 239 Views

In this golang article, we will learn the overview testing package using two test functions as well as using iteration. Testing is of two types: manual testing and automated testing, manual testing is done manually with defined set of test cases whereas in automated testing a program is created with code to test the software. Here we will use two test function as well as iteration method to show the importance of testing package. Algorithm Step 1 −Import the required packages in the program Step 2 − Create a test function in which the function will be called which ...

Read More

Golang program to depict short variable declaration operator(:=)

Akhil Sharma
Akhil Sharma
Updated on 03-May-2023 175 Views

In this golang article, we will write Go language programs to depict short variable declaration operator using var keyword and variable declaration. In shorthand variable, initialization is done at the time of declaration where it’s not necessary in var keyword. Here, we will use a string method, as well as a count variable method to depict short variable declaration. Algorithm Step 1 − Import the required packages in the program Step 2 − Create a main function Step 3 − In the main use short variable declaration to create strings Step 4 − Print the strings created via shorthand ...

Read More

Golang Program to create an empty file

Akhil Sharma
Akhil Sharma
Updated on 03-May-2023 744 Views

In Golang, os and io packages are used for performing various file-r operations like editing, copying, creating, and deleting. In this article, we are going to see three different Examples to create an empty file. In the first Example we will use os.Create from the os package, in the second Example we will use WriteFile function from ioutil package is used and in the third Example we will use NewWriter function from bufio package is used. Syntax os.Create() This function comes from the os package. It helps in the creation of a new file. The filename is given as ...

Read More

Golang Program to read the specified number of characters from the existing file

Akhil Sharma
Akhil Sharma
Updated on 03-May-2023 746 Views

In golang we can use ioutile.ReadFile() to read the file and for loop timer, we will limit the character numbers to read, Os.Open and bufio.NewReader function to perform the execution as well as file.Read() respectively. In this article we will learn how to use the OS asnd bufio package of Golang to read the specified number of characters from the existing file. Syntax ioutil.ReadFile(file) The ReadFile() function is present in ioutil package and is used to read the given file. The function accepts the file to be read as argument to the function. To read a specified number of ...

Read More

Golang Program to open a file in append mode, open if the file does not exist

Akhil Sharma
Akhil Sharma
Updated on 03-May-2023 647 Views

In golang we can os.Openfile function of os package and ioutil.WriteFile() function of ioutil package to append a file. Then, we will use WriteString() function to print the result. In this article, we are going to learn how to create a golang programt to open a file in append mode incase the file does not exist. Syntax os.OpenFile(name/path string, flag int, perm FileMode) The OpenFile() function is present in os package. The function accepts three arguments. One is the name of the file that is to be opened followed by the int type instruction used to open a ...

Read More
Showing 111–120 of 507 articles
« Prev 1 10 11 12 13 14 51 Next »
Advertisements