// FindFile recursively searches upwards from the current directory to the filesystem root for the specified file.
FindFile recursively searches upwards from the current directory to the filesystem root for the specified file.
// FindFile recursively searches upwards from the current directory to the filesystem root for the specified file .
func FindFile(fileName string, dir bool) (string, error) {
	currPath, err := os.Getwd()
	if err != nil {
		return "", fmt.Errorf("failed to find file: %v", err)
	}
	for {
		if currPath == string(os.PathSeparator) || filepath.VolumeName(currPath) == currPath {
			return "", errors.New("failed to find file: reached filesystem root")
		}
		targetFilepath := filepath.Join(currPath, fileName)
		found, err := FileExists(targetFilepath, dir)
		if err != nil {
			return "", fmt.Errorf("failed to find file: %v", err)
		}
		if found {
			return targetFilepath, nil
		}
		currPath = strings.TrimSuffix(currPath, string(os.PathSeparator))
		currPath, _ = filepath.Split(currPath)
	}
}
func FindFile ( fileName string , dir bool ) ( string , error ) { currPath , err := os . Getwd ( ) if err != nil { return " " , fmt . Errorf ( " " , err ) } for { if currPath == string ( os . PathSeparator ) || filepath . VolumeName ( currPath ) == currPath { return " " , errors . New ( " " ) } targetFilepath := filepath . Join ( currPath , fileName ) found , err := FileExists ( targetFilepath , dir ) if err != nil { return " " , fmt . Errorf ( " " , err ) } if found { return targetFilepath , nil } currPath = strings . TrimSuffix ( currPath , string ( os . PathSeparator ) ) currPath , _ = filepath . Split ( currPath ) } }
FindFile recursively searches upwards from the current directory to the filesystem root for the specified file.
FindFile recursively searches upwards from the current directory to the filesystem root for the specified file .
// trimming trailing '/' causes filepath.Split to trim the last directory in currPath