Found 33676 Articles for Programming

Golang program to copy one file into another file

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

4K+ 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: Using OS Package In this illustration, the program initially uses the os.Open function to open the source file, source.txt. Then it uses the os.Generate function to create the destination file, destinaton.txt. Then, io.Copy function is used to copy the contents of the source file to the target file. Syntax os.Open ... Read More

Golang Program to rename a specified file by another name

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 package respectively. Method 1: Using OS Package In this method, we will write a go language program to rename a specified file by another name by using the Rename() function present in os package. Syntax func Rename(oldpath, newpath string) error The Rename() function is present in os package and ... Read More

Golang Program to check a specified file is exist or not

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

979 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() and ReadFile() function respectively. Method 1: Using STAT() Method In this method, we will use the Stat function present in os package to check if the file exists or not. Syntax Stat(file string) The stat() function is present in os package and is used to get the status of ... Read More

Golang Program to check a file has writable permission or not

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

3K+ 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 present in the os package respectively. Method 1: Using OpenFile() Method In this method, we will use the OpenFile() function to check the write permission of a file. This function opens a file with the given name and options, and returns a pointer to a File structure. Syntax func OpenFile(name ... Read More

Golang Program to check a directory is exist or not

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

7K+ 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 example we are using Open() and mkdir() function respectively to implement the result. Method 1: Using os.stat() Method The os package provides the Stat() function to get information about a file or directory. If the directory exists, the function returns a FileInfo structure, otherwise, it returns an error. Syntax func ... Read More

Golang Program to remove a specified directory

Akhil Sharma
Updated on 22-Feb-2023 14:25:39

5K+ Views

Golang provides several methods to remove a specified directory, including using the os and filepath packages. Removing a directory is a critical operation, and caution should be exercised when performing this task. This article will discuss the different methods to remove a directory in Golang, along with the syntax and algorithm for each method. Method 1: Using The os Package The os package in Golang provides several functions to perform operating system-related operations, including removing a directory. The Remove function of the os package is used to remove a directory. Syntax Remove(dirName) The Remove() function is present in os ... Read More

Why can’t a Priority Queue wrap around like an ordinary Queue?

Sonal Meenu Singh
Updated on 22-Feb-2023 16:09:59

393 Views

Introduction A queue is an abstract Data type that inserts elements from the Rear end and removes them from the Front end. There are three types of queues: Simple Queue, Priority Queue, and Circular Queue. In this tutorial, we understand why we cannot wrap around a Priority queue and the reasons for it. Priority Queue It is a unique queue that is not based on the FIFO principle for Queue operations. What makes it unique? It is the priority of its elements for removing or deQueue. Each element of the priority queue has some priority and they are removed based ... Read More

Golang Program to get the list the name of files in a specified directory

Akhil Sharma
Updated on 22-Feb-2023 14:24:24

5K+ Views

In Golang, we have two internal functions - ReadDir() and Walk function to get a list of filenames prenent in a specific directory. Here we have write three examples. In the first example We will use the ReadDir() function present in ioutil package while in the second one we are using the walk function present in the filepath package. Method 1: Using ioutil PACKAGE The ioutil package in Golang provides several functions to perform input/Output operations, including reading the files and directories. The ReadDir() function of the ioutil package is used to get the list of files in a specified ... Read More

Turn a Queue into Priority Queue

Sonal Meenu Singh
Updated on 22-Feb-2023 15:59:12

1K+ Views

Introduction A queue is a linear data structure that follows the FIFO principle for inserting and removing elements and has no close ending. It is functional on both ends. In this tutorial, we will learn how to turn a queue into a priority Queue and understand the meaning of queue and priority queue in the data structure. What is Queue? Queue in data structure resembles the queue in real life and is used to handle multiple data. It is an ordered list in which elements are entered on the rear end and removed from the front end. In this, the ... Read More

Time and Space Complexity Analysis of Queue operations

Sonal Meenu Singh
Updated on 22-Feb-2023 15:51:25

3K+ Views

Introduction Queue is a linear data structure that uses the FIFO approach for inserting and removing its elements. It can be implemented by using arrays and linked lists. In this tutorial, we will analyze the time and space complexity of array based queue for its different operation. Queue Implementation Using Array The principle of Queue is its FIFO approach and it states that the element that enters first in the Queue will be the first to be removed from it. Its elements are inserted at the Rear end. Queue elements are removed from the Front end. The real-life example of ... Read More

Advertisements