title: Modyfying access times of all files in a directory using python
body: <p>I am a beginner in python and trying to modify access times (<code>touch</code>) of sub-directories and files of a parent directory. I found that how to modify access time of a file here <a href="https://stackoverflow.com/questions/1158076/implement-touch-using-python">Implement touch using Python?</a></p>
  
  <blockquote>
  <pre><code>import os
  def touch(fname, times=None):
      with open(fname, 'a'):
          os.utime(fname, times)
  </code></pre>
  </blockquote>
  
  <p>instead of <code>fname</code> above, I want to have sub-directories and files of a parent directory. So I found another question of looping through directories: <a href="https://stackoverflow.com/questions/19587118/iterating-through-directories-with-python">Iterating through directories with Python</a></p>
  
  <blockquote>
  <pre><code>import os
  rootdir = 'C:/Users/sid/Desktop/test'
  
  for subdir, dirs, files in os.walk(rootdir):
      for file in files:
          print os.path.join(subdir, file)
  </code></pre>
  </blockquote>
  
  <p>Combining code from above examples, I created code: </p>
  
  <pre><code>import os
  rootdir = '/usr/sf/adir'
  
  for subdir, dirs, files in os.walk(rootdir):
      for file in files:
          fname = os.path.join(subdir, file)
          def touch(fname, times=None):
              with open(fname, 'a'):
                  os.utime(fname, times)
  </code></pre>
  
  <p>The code runs without errors, but when I did <code>ls -l</code>, I could not see access time stamp modified. Where am I going wrong? Is the third code correct to <code>touch</code> all files and sub-directories? </p>
  
  <p>I am using python 2.6.</p>