
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 26504 Articles for Server Side Programming

5K+ Views
To get the relative path from two absolute paths in golang, we use filepath and string packages. Relative paths tell the location of file with respect to present working directory whereas absolute paths tell the location of file starting from root directory. In the first method we will use filepath package functions and in the second method we will use strings package function. Method 1: Using Filepath Package In this program, the base name of the file, which is the file name without the directory path, is extracted using the filepath.Base function from the path/filepath package. The name of the ... Read More

11K+ 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 will use strings package functions. Method 1: Using filepath Package The base name of the file, which is the file name without the directory path, is extracted in this program using the filepath.Base function from the path/filepath package. The name of the extracted file is then displayed on the console. ... Read More

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 Function In this method, a directory named dirName variable is created using the os.Mkdir function. The permission bits for the new directory are the second input to os.Mkdir, which we set to 0755. (read, write, and execute permissions for the owner and read and execute permissions for others). The program ... Read More

2K+ 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 file to read. It takes one input i.e. the filename which will be opened. os.RemoveAll It removes the directory and its contents completely. The function takes the name of the directory as an argument. dr.ReaddirNames This function is useful to read the file names from a directory. ... Read More

801 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 to newname.txt using the Rename function. If the renaming does not occur, such as if the source file doesn't exist or if the destination file already exists, the function produces an error by panicking. The error will be nil if the renaming procedure is successful. Syntax os.Rename os.Rename is ... Read More

5K+ 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 deleting a file. Syntax os.Remove() The os.Remove function in Go is used to delete a file or directory identified by a file path. The file or directory path that you want to remove is the only argument for this function. Algorithm Step 1 − Create a package main ... Read More

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

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

985 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

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