<p>Got a list of config files that reside outside of templates folder that we feed into a helm chart like the following: </p>

<pre><code>├── configs
│   ├── AllEnvironments
│   │   ├── Infrastructure
│   │   └── Services
│   │       ├── ConfigFile1
│   │       ├── ConfigFile2
│   ├── Apps
│   │   ├── App1
│   │   ├── App2
│   │   └── App3
│   ├── ManagementEnvironments
│   │   ├── Database
│   │   │   ├── DbFile1
│   │   │   └── DbFile2
│   │   ├── Infrastructure
│   ├── TestEnvironments
│   │   ├── Pipeline
│   │   │   └── Pipeline1
│   │   ├── Database
│   │   │   ├── Pipeline2
│   ├── Console
│   │   ├── Console1
│   │   ├── Console2
</code></pre>

<p>It works out good for us so far. Now we need to parse the folders and get a list of all the folders under configs that do not end with Environments. So basically a range that would include Apps and Console in this case.</p>

<p>Doing the following I get a repetition of Apps 3 times as that many files are under it and also Console 2 times. </p>

<p>I would like to get a list of folders that do not end with Environments only once.</p>

<p>I tried to look at the Go templates and some helm chart toolkits but I have no experience in Go which seems like a requirement to make this happen and I will probably take on the next few days. But for now I'm stuck, so any help is appreciated.</p>

<pre><code>{{- range $path, $bytes  := $.Files.Glob "configs/**" }}
{{- if not (or (dir $path | regexFind "configs.*Environments.*")  (dir $path | regexFind "configs$")) }}
 {{ base (dir $path) }}

{{- end }}
{{- end }}
</code></pre>

<p>Here is a way to do it if it will help anyone else:</p>

<p>Helm charts uses Go template and Sprig library. So using a dict from Sprig we can keep the previous value of the folder that we are listing and we print it out only if the current folder is different from the previous one. Now this works as the files are listed in alphabetical order so files on the same folder will be consecutive. If they were to be read without order these approach would not work. </p>

<pre><code>{{- $localDict := dict "previous" "-"}}
{{- range $path, $bytes  := $.Files.Glob "configs/**" }}
{{- if not (or (dir $path | regexFind "configs.*Environments.*")  (dir $path | regexFind "configs$")) }}
{{- $folder := base (dir $path) }}
{{- if not (eq $folder $localDict.previous)}}
    {{$folder -}}
{{- end }}
{{- $_ := set $localDict "previous" $folder -}}
{{- end }}
{{- end }}
</code></pre>
