Skip to content

Instantly share code, notes, and snippets.

@neomantra
Created May 21, 2024 22:45
Show Gist options
  • Save neomantra/b1bfb419a067bb368d1c816d7190b97e to your computer and use it in GitHub Desktop.
Save neomantra/b1bfb419a067bb368d1c816d7190b97e to your computer and use it in GitHub Desktop.
VerifyDirectoryExists
func VerifyDirectoryExists(dirPath string) error {
if fileInfo, err := os.Stat(dirPath); err != nil {
if os.IsNotExist(err) {
return fmt.Errorf("directory '%s' does not exist", dirPath)
} else {
return fmt.Errorf("error filestat on '%s': %w", dirPath, err)
}
} else if !fileInfo.IsDir() {
return fmt.Errorf("'%s' exists but is not a directory", dirPath)
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment