title: python how to solve errno 13 permission denied using shutil?
body: <p>Hi im new to python and im trying to make a script to sort songs but I keep getting permission errors. The script is able to make the folders but when it comes to copying the file (line 32 shutil.copy(inPath, artistFolder + albumFolder) the error comes up.</p>
  <p>I have tried changing windows folder permissions running python and vs code as admin as well as using different shutil copy commands (copy, copy2, copyfile and move). I've also tried using different folders on different drives. Using windows 11 and python version 3.10.6.</p>
  <pre><code>#Import nessesary libraries
  import shutil, os
  from tinytag import TinyTag
  
  # Define music file
  music_filetype = ('mp3', 'm4a', 'flac', 'wav')
  
  def main():
      print('start')
  
      #Specify input and output directory
      inPath = 'D:\\Music\Test'
      outPath = 'D:\\Music'
  
      for root, dirs, files in os.walk(inPath):
          for file in files:
              if (file.endswith(music_filetype)):
                  print(root+&quot;/&quot;+str(file))
                     
                  #try:
  
                  temp_track = TinyTag.get(root + '\\' + file) # temp_track is variable used to access audio tags
                  artistFolder = outPath + '/' + temp_track.albumartist # Create folder named for artist
                  albumFolder = temp_track.album # Create folder for album
  
  
                  if os.path.exists(artistFolder): #check if artist folder exists
                      print('folder found')
                      if os.path.exists(artistFolder + albumFolder): #check if album folder exists
                          shutil.copy(inPath, artistFolder + albumFolder) #copy song to folder if folders exist
  
                  elif not os.path.exists(artistFolder + albumFolder): #check if folders don't exist
                      os.makedirs(artistFolder) #create folders
                      os.makedirs(artistFolder + albumFolder)
                      shutil.copy(inPath, artistFolder + albumFolder) #copy song
  
                  #except Exception:
                      #print(root+&quot;/&quot;+str(file), &quot; Error&quot;)
  
  main()
  </code></pre>
  <pre><code>Exception has occurred: PermissionError
  [Errno 13] Permission denied: 'D:\\Music\\Test'
    File &quot;D:\Users\User\Documents\Python_projects\Music_sorter\Music_sorter.py&quot;, line 32, in main
      shutil.copy(inPath, artistFolder + albumFolder) #copy song to folder if folders exist
  
  </code></pre>