ADVERTISEMENT
ADVERTISEMENT

Golang os.IsNotExist() Function with Examples

Golang | os.IsNotExist() Function: Here, we are going to learn about the IsNotExist() function of the os package with its usages, syntax, and examples.
Submitted by IncludeHelp, on November 25, 2021

os.IsNotExist()

In the Go language, the os package provides a platform-independent interface to operating system (Unix-like) functionality. The IsNotExist() function is an inbuilt function of the os package, it is used to check whether the given error is known to report that a file or directory does not exist. The IsNotExist() function is satisfied by ErrExist as well as some syscall errors. This function predates errors.Is.

It accepts one parameter (err error) and returns a boolean indicating whether the error is known to report that a file or directory does not exist.

Syntax:

func IsNotExist(err error) bool

Parameter(s):

  • err - Error

Return Value:

The return type of the os.IsNotExist() function is a bool, it returns a boolean indicating whether the error is known to report that a file or directory does not exist.

Example:

// Golang program to demonstrate the
// example of IsNotExist() function

package main

import (
	"fmt"
	"os"
)

func main() {
	_, err := os.Stat("/path/to/file")
	fmt.Println("err:", err)

	x := os.IsNotExist(err)
	fmt.Println("x:", x)
}

Output:

err: stat /path/to/file: no such file or directory
x: true

Golang os Package »


ADVERTISEMENT




ADVERTISEMENT



Comments and Discussions!

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.