// FindFileInDirAndParents looks for a file named fileName in dirPath and its parents, and returns the path of the directory where it was found.
// dirPath must be a full path.
FindFileInDirAndParents looks for a file named fileName in dirPath and its parents, and returns the path of the directory where it was found.
dirPath must be a full path.
// FindFileInDirAndParents looks for a file named fileName in dirPath and its parents and returns the path of the directory where it was found . // dirPath must be a full path .
func FindFileInDirAndParents(dirPath, fileName string) (string, error) {
	visitedPaths := make(map[string]bool)
	currDir := dirPath
	for {
		exists, err := IsFileExists(filepath.Join(currDir, fileName), true)
		if err != nil || exists {
			return currDir, err
		}
		visitedPaths[currDir] = true
		currDir = filepath.Dir(currDir)
		if visitedPaths[currDir] {
			return "", errors.New(fmt.Sprintf("could not find the %s file of the project", fileName))
		}
	}
}
func FindFileInDirAndParents ( dirPath , fileName string ) ( string , error ) { visitedPaths := make ( map [ string ] bool ) currDir := dirPath for { exists , err := IsFileExists ( filepath . Join ( currDir , fileName ) , true ) if err != nil || exists { return currDir , err } visitedPaths [ currDir ] = true currDir = filepath . Dir ( currDir ) if visitedPaths [ currDir ] { return " " , errors . New ( fmt . Sprintf ( " " , fileName ) ) } } }
FindFileInDirAndParents looks for a file named fileName in dirPath and its parents, and returns the path of the directory where it was found.
FindFileInDirAndParents looks for a file named fileName in dirPath and its parents and returns the path of the directory where it was found .
// Create a map to store all paths visited, to avoid running in circles. // If the file is found in the current directory, return the path. // Save this path. // CD to the parent directory. // If we already visited this directory, it means that there's a loop and we can stop.