Skip to content

osexistpath can check whether a path, file, or directory exists.

License

Notifications You must be signed in to change notification settings

yyle88/osexistpath

Repository files navigation

GitHub Workflow Status (branch) GoDoc Coverage Status Supported Go Versions GitHub Release Go Report Card

osexistpath - A Go Library for Checking Path, File, and Directory Existence

Introduction

osexistpath is designed to check whether a path, file, or directory exists.

CHINESE README

中文说明

Features

  • IsPathExists: Checks whether a path exists.
  • IsFileExists: Checks whether a file exists.
  • IsRootExists: Checks is a directory exists.
  • PATH, FILE, ROOT: Functions that return the path if it exists, otherwise raise a panic.

Installation

go get github.com/yyle88/osexistpath

Usage

Example 1: Checking if a Path Exists

package main

import (
	"fmt"
	"github.com/yyle88/osexistpath"
)

func main() {
	// Check if a path exists using the "Might" verbosity level
	path := "/some/path"
	exist, err := osexistpath.IsPathExists(path, osexistpath.Might)
	if err != nil {
		fmt.Println("Error:", err)
	} else {
		fmt.Println("Path exists:", exist)
	}
}

Example 2: Checking if a File Exists

package main

import (
	"fmt"
	"github.com/yyle88/osexistpath"
)

func main() {
	// Check if a file exists using the "Sweet" verbosity level
	file := "/some/file.txt"
	exist, err := osexistpath.IsFileExists(file, osexistpath.Sweet)
	if err != nil {
		fmt.Println("Error:", err)
	} else {
		fmt.Println("File exists:", exist)
	}
}

Example 3: Checking if a Directory Exists

package main

import (
	"fmt"
	"github.com/yyle88/osexistpath"
)

func main() {
	// Check if a directory exists using the "Noisy" verbosity level
	dir := "/some/directory"
	exist, err := osexistpath.IsRootExists(dir, osexistpath.Noisy)
	if err != nil {
		fmt.Println("Error:", err)
	} else {
		fmt.Println("Directory exists:", exist)
	}
}

License

osexistpath is open-source and released under the MIT License. See the LICENSE file for more information.


Support

Welcome to contribute to this project by submitting pull requests or reporting issues.

If you find this package helpful, give it a star on GitHub!

Thank you for your support!

Happy Coding with osexistpath! 🎉

Give me stars. Thank you!!!

See stars

see stars