title: Go - Iterate through directores/files in current directory
body: <p>I have the following structure:</p>
  
  <pre><code>project/
      docs/
          index.html
      root.html
  </code></pre>
  
  <p>I'm trying to iterate through this project structure so that I can read the contents of each file to process them. So I want to say "search through the directory project", then it will search through all the files, and only the <strong>first level of directories</strong> and their files, so if there was another directory with a file inside of <code>docs/</code>, it would ignore it. </p>
  
  <p>Currently, I've tried to accomplish this with the "path/filepath" library:</p>
  
  <pre><code>func traverse(path string, file os.FileInfo, err error) error {
      if file, err := os.Open(file.Name()); err == nil {
          defer file.Close()
          if fileStat, err := file.Stat(); err == nil {
              switch mode := fileStat.Mode(); {
              case mode.IsDir():
                  fmt.Println("it be a directory! lets traverse", file.Name())
                  filepath.Walk(file.Name(), traverse)
              case mode.IsRegular():
                  fmt.Println("the thingy ", file.Name(), " is a file")
              }
          } else {
              return errors.New("failed to check status")
          }
      }
      return errors.New("failed 2 open file/dir?")
  }
  </code></pre>
  
  <p>Then I call it from here:</p>
  
  <pre><code>if err := filepath.Walk("project/", traverse); err != nil {
      setupErr("%s", err)
  }
  </code></pre>
  
  <p>Note that I run this executable relative to my test directory, so it's finding the directory okay. My problem is actually when I run it, I get the following:</p>
  
  <pre><code>it be a directory! lets traverse project
  it be a directory! lets traverse project
  # ^ printed about 20 more times ^
  failed 2 open file/dir?
  </code></pre>
  
  <p>I think my recursion is a little off, and it's not changing into the directory perhaps? Any ideas, if you need any more information just ask and I'll update.</p>