From e19845c2029fb3dcb6a00c26fd5b43b4fab524ef Mon Sep 17 00:00:00 2001
From: Cameron Sparr <cameronsparr@gmail.com>
Date: Wed, 28 Sep 2016 15:30:02 +0100
Subject: [PATCH] Load config directory using filepath.Walk

closes #1137
---
 CHANGELOG.md              |  1 +
 internal/config/config.go | 19 ++++++++-----------
 2 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1c97c17e..bd06cc51 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -37,6 +37,7 @@
 - [#1751](https://github.com/influxdata/telegraf/issues/1751): Fix powerdns integer parse error handling.
 - [#1752](https://github.com/influxdata/telegraf/issues/1752): Fix varnish plugin defaults not being used.
 - [#1517](https://github.com/influxdata/telegraf/issues/1517): Fix windows glob paths.
+- [#1137](https://github.com/influxdata/telegraf/issues/1137): Fix issue loading config directory on windows.
 
 ## v1.0.1 [unreleased]
 
diff --git a/internal/config/config.go b/internal/config/config.go
index 30e62789..077aa307 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -404,24 +404,21 @@ func PrintOutputConfig(name string) error {
 }
 
 func (c *Config) LoadDirectory(path string) error {
-	directoryEntries, err := ioutil.ReadDir(path)
-	if err != nil {
-		return err
-	}
-	for _, entry := range directoryEntries {
-		if entry.IsDir() {
-			continue
+	walkfn := func(thispath string, info os.FileInfo, _ error) error {
+		if info.IsDir() {
+			return nil
 		}
-		name := entry.Name()
+		name := info.Name()
 		if len(name) < 6 || name[len(name)-5:] != ".conf" {
-			continue
+			return nil
 		}
-		err := c.LoadConfig(filepath.Join(path, name))
+		err := c.LoadConfig(thispath)
 		if err != nil {
 			return err
 		}
+		return nil
 	}
-	return nil
+	return filepath.Walk(path, walkfn)
 }
 
 // Try to find a default config file at these locations (in order):
-- 
GitLab