title: Python: Why am I getting [Errno 13] Permission Denied?
body: <p>I am trying to write some code that searches a group of files for a string and then places any files that include the string into a different directory which at the start of the program will not exist. </p>
  
  <pre><code>import os
  import re
  
  def test():
      os.chdir("C:/Users/David/Files/TestFiles")
      files = os.listdir(".")
      os.mkdir("C:/Users/David/Files/TestFiles2")
      for x in (files):
          inputFile = open((x), "r")
          content = inputFile.read()
          inputFile.close()
          if "Hello Word" in content:
              with open ("C:/Users/David/Files/TestFiles2", "w") as outputFile:
                  outputFile.write(content)
  </code></pre>
  
  <p>When it runs I get the following error message</p>
  
  <pre><code>PermissionError: [Errno 13] Permission denied: 'C:/Users/David/Files/TestFiles2'
  </code></pre>
  
  <p>Just wondering if anyone can tell me why this error message appears.</p>