title: Python's os.walk and case sensitivity on Ubuntu?
body: <p>I've got a bit of a strange situation that has me a bit stumped.  I'm trying to perform a file system search of all sub-directories of a specified path.  I want to return results, respecting the user's desire for a case-sensitive or case-insensitive search.  This seems to work fine on Windows, but is giving me a bit of a headache when running the same code on Python. </p>
  
  <p>For the sake of testing things, I've stripped out some code of the main application into a small snippet of python code, like so:</p>
  
  <pre><code>import sys
  import os
  
  src = sys.argv[1]
  caseSensitive = sys.argv[2]
  searchText = sys.argv[3]
  
  if caseSensitive == False:
      searchText = searchText.lower()
  
  print "Case sensitive: " + caseSensitive
  print "Src: " + src
  print "Search text: " + searchText
  fileCount = 0
  directoryCount = 0;
  
  if caseSensitive == True:
      print "Performing case sensitive search..."
  else:
      print "Performing case insensitive search..."
  
  
  for root, dirnames, filenames in os.walk(src):
      for directory in dirnames:
          if caseSensitive == True:
              dMatch = directory
          else:
              dMatch = directory.lower()
  
          print "D:" + dMatch
          if dMatch.find(searchText) != -1:
              print "    **************dir match: " + dMatch
              directoryCount = directoryCount + 1
      for filename in filenames:
          if caseSensitive == True:
              fMatch = filename
          else:
              fMatch = filename.lower()
  
          print "F:" + fMatch
  
          if fMatch.find(searchText) != -1:
              print "    **************file match: " + fMatch
              fileCount = fileCount + 1
  
  print "Matching files: "
  print fileCount
  print "Matching directories: "
  print directoryCount
  </code></pre>
  
  <p>It's a bit of a rough sample, but it at least gives a general idea of what I'm doing.  </p>
  
  <p>Suppose that I have a directory structure as follows:</p>
  
  <pre><code>Foo
    --bar
    --Fizz
       --Buzz
         --Buzz.txt
  </code></pre>
  
  <p>If I run the script and point it at the Foo directory, and tell it to do a case-sensitive search for the word "Bu", on Windows it will find the Buzz directory and Buzz.txt.  </p>
  
  <p>If I run the same snippet on Ubuntu, it won't return any results at all, unless I ignore the case.  When printing out the directories and file names that are encountered by os.walk(), it prints them all in lowercase.  This would partially explain why the search is failing when running on Ubuntu - it won't ever find a match because it is comparing a mixed case "Bu" against "bu", which won't register as a match.</p>
  
  <p>Long story short: am I missing something, or are the results from os.walk() on Ubunut always returned in lower-case?</p>