title: Python program to traverse directories and read file information
body: <p>I'm just getting started with Python but already have found it much more productive than Bash shell scripting.</p>
  
  <p>I'm trying to write a Python script that will traverse every directory that branches from the directory I launch the script in, and for each file it encounters, load an instance of this class:</p>
  
  <pre><code>class FileInfo:
  
      def __init__(self, filename, filepath):
          self.filename = filename
          self.filepath = filepath
  </code></pre>
  
  <p>The filepath attribute would be the full absolute path from root (/).  Here's the pseudocode mockup for what I'd like the main program to do:</p>
  
  <pre><code>from (current directory):
  
      for each file in this directory, 
      create an instance of FileInfo and load the file name and path
  
      switch to a nested directory, or if there is none, back out of this directory
  </code></pre>
  
  <p>I've been reading about os.walk() and ok.path.walk(), but I'd like some advice about what the most straightforward way to implement this in Python would be. Thanks in advance.</p>