title: Trying to fetch all the files (including read only) from a directory using Python
body: <p>I am new to Python - please excuse me if my question looks dumb.</p>
  
  <p>I am trying to fetch all the files present in a given folder and create an Excel which shows file name and path. </p>
  
  <p>It works fine on some folders, but not all. The reason which I think is maybe it's unable to fetch the data which is in read only mode (I am not quite sure of this). </p>
  
  <p>Here is the error which I get:</p>
  
  <blockquote>
    <p>F:/<br>
    Traceback (most recent call last):<br>
    File "c:/Vamsi_Folder/4.Tutorials/Python/OS/01-WIP/Get Files From  Directory/Get_Files_From_Directory.py", line 36, in <br>
    List = getListOfFiles(filename)</p>
    
    <p>File "c:/Vamsi_Folder/4.Tutorials/Python/OS/01-WIP/Get Files From Directory/Get_Files_From_Directory.py", line 30, in getListOfFiles<br>
    allFiles = allFiles + getListOfFiles(fullPath)</p>
    
    <p>File "c:/Vamsi_Folder/4.Tutorials/Python/OS/01-WIP/Get Files From Directory/Get_Files_From_Directory.py", line 22, in getListOfFiles<br>
    listOfFile = os.listdir(dirName)</p>
    
    <p>PermissionError: [WinError 5] Access is denied: 'F:/System Volume Information'</p>
  </blockquote>
  
  <p>Here is the code which I am using:</p>
  
  <pre><code>#program to write files from directory in Excel
  
  
  import os
  from openpyxl import Workbook
  from openpyxl.worksheet.table import Table, TableStyleInfo
  import numpy as np
  from tkinter import Tk
  from tkinter.filedialog import askdirectory
  from tkinter.filedialog import asksaveasfilename
  import ntpath
  
  
  Tk().withdraw()
  filename = askdirectory()
  print(filename)
  
  
  def getListOfFiles(dirName):
      # create a list of file and sub directories 
      # names in the given directory 
      listOfFile = os.listdir(dirName)
      allFiles = list()
      # Iterate over all the entries
      for entry in listOfFile:
          # Create full path
          fullPath = os.path.join(dirName, entry)
          # If entry is a directory then get the list of files in this directory 
          if os.path.isdir(fullPath):
              allFiles = allFiles + getListOfFiles(fullPath)
          else:
              allFiles.append(fullPath)
  
      return allFiles
  
  List = getListOfFiles(filename)
  Filename = []
  for i in List:
      Filename.append(ntpath.basename(i))
  
  
  workbook = Workbook()
  worksheet = workbook.active
  worksheet.title = "Directory"
  
  outlist = [Filename,List]
  
  transpose = np.array(outlist).T
  transpose_outlist = transpose.tolist()
  
  worksheet.append(["Filename","Path"])
  
  for row in transpose_outlist:
      worksheet.append(row)
  
  count = "A1:""B"+str(len(List)+1)
  
  tab = Table(displayName="Directory", ref=count)
  style = TableStyleInfo(name="TableStyleMedium9", showFirstColumn=False,
                         showLastColumn=False, showRowStripes=True, showColumnStripes=True)
  tab.tableStyleInfo = style
  worksheet.add_table(tab)
  
  savename =asksaveasfilename(initialdir = "/",defaultextension="*.*",filetypes=\
                                       (("xml files","*.xml"),\
                                        ('xlsx files','.xlsx'),\
                                        ("all files","*.*")))
  
  workbook.save(savename)
  </code></pre>