fs

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 1, 2021 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package fs contains utilities to check if files or directories exist and closing files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CloseFile

func CloseFile(file *os.File)

CloseFile closes the file and handles the error if it occurs by printing it out and exiting with a code of 1.

Example:

file, err := os.Open(filePath)
... handle error
defer fs.CloseFile(file)

func DirExists

func DirExists(dirPath string) (bool, error)

DirExists checks if a directory exists.

The given dirPath should be an absolute path. Returns true if the directory exists; false otherwise.

Example:

 exists, err := fs.DirExists(dirPath)
	if err != nil {
   ... handle error
 }

 if exists {
   ... do work
 }

func FileExists

func FileExists(filePath string) (bool, error)

FileExists checks if a file exists and is not a directory.

The given filePath should be an absolute path. Returns true if the file exists; false otherwise.

Example:

 exists, err := fs.FileExists(filePath)
	if err != nil {
   ... handle error
 }

 if exists {
   ... do work
 }

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL