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"
#13
(Feb-09-2020, 04:53 AM)jim2007 Wrote: Have a read of this, it should get you off the starting block in finding a list of files: https://realpython.com/working-with-files-in-python/

Thank you it was good read, I guess I don't have the experience or logic to read that kind of thing and apply to my case yet. Still waiting for a solution (lost hope already though)

Asked the same question on reddit, stackoverflow, python forum etc. Either the idea of helping others online is just vanished or helping others in programming is not similar to other practices. I have been a sound engineer for more than 13 years, I have spent countless hours helping newbies (including programmers) to solve their audio related problems. It's sad when you need the same help you can't find anyone to help.

I appreciate your help and interest again.

import os
 
'''
    For the given path, get the List of all files in the directory tree 
'''
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        
 
 
def main():
    
    dirName = '/home/varun/Downloads';
    
    # Get the list of all files in directory tree at given path
    listOfFiles = getListOfFiles(dirName)
    
    # Print the files
    for elem in listOfFiles:
        print(elem)
 
    print ("****************")
    
    # Get the list of all files in directory tree at given path
    listOfFiles = list()
    for (dirpath, dirnames, filenames) in os.walk(dirName):
        listOfFiles += [os.path.join(dirpath, file) for file in filenames]
        
        
    # Print the files    
    for elem in listOfFiles:
        print(elem)    
        
        
        
        
if __name__ == '__main__':
    main()
I guess this script now prints out all the files in my directory, including subdirectories. Now I gotta find out how to extract them all and I should be all set.
Reply


Messages In This Thread
RE: Fixing "PermissionError: [Errno 13] Permission denied" - by puredata - Feb-10-2020, 03:45 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 883 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,206 Jun-21-2022, 11:11 PM
Last Post: Larz60+
  Permission issue when using scapy jao 3 10,542 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