check if path is directory golang code example
Example: golang check if a path contains a valid directory
dir, err := os.Stat(dirName)
if err != nil {
return filesHash, fmt.Errorf("failed to open directory, error: %w", err)
}
if !dir.IsDir() {
return filesHash, fmt.Errorf("%q is not a directory", dir.Name())
}