title: looping over markings in files based on userstrings
body: <p>I have the following piece of code which I use to check for copyright markings.  I currently only check for userstring1.  Now I want to check for multiple userstrings.  What is the best way to modify the following code so that:</p>
  
  <ul>
  <li>all the files being checked are checked for all userstrings</li>
  <li><p>the filename of each file that matches any string is printed</p>
  
  <pre><code>import os
  import sys
  import fnmatch
  
  userstring1="Copyright (c) 2012 Company, Inc\nAll Rights Reserved.\nCompany Confidential and Proprietary."
  userstring2="Copyright (c) 2011-2013 Company, Inc\nAll Rights Reserved.\nCompany Confidential and Proprietary."
  #print len(sys.argv)
  #print sys.argv[1]
  if len(sys.argv) &lt; 2:
      sys.exit('Usage: check_copyright.py &lt;build directory&gt;')
  '''
  for r,d,f in os.walk(sys.argv[1]):
      for files in f:
          userlines = userstring.split('\n') # Separate the string into lines
          with open(os.path.join(r, files), "r") as file:
  '''
  for path,dirs,files in os.walk(sys.argv[1]):
      for fname in files:
          userlines = userstring1.split('\n') # Separate the string into lines 
          # Test the filename for particular pattern matches.
          for pat in ['*.cpp','*.c','*.h']:
              if fnmatch.fnmatch(fname,pat):
                  fullname = os.path.join(path,fname)
                  with open(fullname) as file:
                      match = 0
                      for line in file:
                          if userlines[match] in line: # Check if the line at index `m` is in the user lines
                              match += 1 # Next time check the following line
                          elif match &gt; 0: # If there was no match, reset the counter
                              match = 0
                          if match &gt;= len(userlines): # If 3 consecutive lines match, then you found a match
                              break
                      if match == len(userlines): # print if you found a match
                          print "MATCH"
                          print match
                          print "LENGTH userlines"
                          print len(userlines)
                      print fullname
  </code></pre></li>
  </ul>