Created
May 21, 2024 22:45
-
-
Save neomantra/b1bfb419a067bb368d1c816d7190b97e to your computer and use it in GitHub Desktop.
VerifyDirectoryExists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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