Python Forum
Fixing "PermissionError: [Errno 13] Permission denied"
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Fixing "PermissionError: [Errno 13] Permission denied"
#14
So I did the same, but it is a function that returns a list of files:

import os
from typing import List

FileList = List[str]

def get_list_of_files(base_folder: str, files: FileList) -> None:
    with os.scandir(base_folder) as entries:
        for entry in entries:
            # Skip all hidden files and folders
            if entry.name.startswith('.'):
                continue

            qualified_name = os.path.join(base_folder, entry)

            # If it's a file we'll added it to the collection
            if entry.is_file():
                files.append(qualified_name)
            elif entry.is_dir():
                # If it's a folder then we'll process that as well
                get_list_of_files(os.path.join(base_folder, entry), files)

files = []
base_folder = '/Users/<user>/Development'

get_list_of_files(base_folder, files)

for file in files:
    print(file)
You pass it the base folder and an empty list and it will populate it for you.

PS - I'm just learning Python as well, but I have 30+ years of coding behind me.
There is no passion to be found playing small - in settling for a life that is less than the one you are capable of living.
Reply


Messages In This Thread
RE: Fixing "PermissionError: [Errno 13] Permission denied" - by jim2007 - Feb-10-2020, 04:51 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Circumvent the "access denied" page? Pedroski55 7 272 Jun-15-2024, 06:25 AM
Last Post: Pedroski55
  The INSERT permission was denied on the object Steven5055 3 1,711 Jun-12-2024, 08:13 AM
Last Post: GregoryConley
  Delete file with read-only permission, but write permission to parent folder cubei 6 22,381 Jun-01-2024, 07:22 AM
Last Post: Eleanorreo
  KivyMD android app - problem with permission polak7gt 0 382 Jan-18-2024, 01:27 PM
Last Post: polak7gt
  Potential Permission error on Mac OSX Catalina OWOLLC 1 884 Nov-02-2023, 07:52 AM
Last Post: unjnsacih
  logging: change log file permission with RotatingFileHandler erg 0 1,213 Aug-09-2023, 01:24 PM
Last Post: erg
  (python) Can i get some help fixing a English to Morse translator? Pls AlexPython 7 1,748 Sep-12-2022, 02:55 AM
Last Post: AlexPython
  access is denied error 5 for network drive mapping ? ahmedbarbary 2 1,917 Aug-17-2022, 10:09 PM
Last Post: ahmedbarbary
  Server Folder Error : WinError5 Access Denied fioranosnake 1 1,207 Jun-21-2022, 11:11 PM
Last Post: Larz60+
  Permission issue when using scapy jao 3 10,543 Feb-05-2022, 06:14 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020