Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7062271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:34:26+00:00 2026-05-28T04:34:26+00:00

in Python glob ignores Permission denied errors. Unfortunately I need to know if there

  • 0

in Python glob ignores “Permission denied” errors. Unfortunately I need to know if there was a directory which I can’t read.

I could use os.walk() and fnmatch, but maybe there is a better solution?

Example:

user@pc:~
===> python
>>> import glob
>>> glob.glob('/root/*')
[]

There are files in /root, but user@pc is not allowed to read this directory.

A single Exception would not be enough. For example glob.glob('/var/log/*/*.log'). I want to know which directories exist, but are unreadable.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:34:27+00:00Added an answer on May 28, 2026 at 4:34 am

    One way to get all the directories and files that cannot be read is indeed use os.walk to traverse recursively a directory tree and then, for every directory and file, check permissions using os.access:

    import os
    
    unreadable_dirs = []
    unreadable_files = []
    
    for dirpath, dirnames, filenames in os.walk('/var/log'):
      for dirname in dirnames:
        dirname = os.path.join(dirpath, dirname)
        if not os.access(dirname, os.R_OK):
          unreadable_dirs.append(dirname)
      for filename in filenames:
        filename = os.path.join(dirpath, filename)
        if not os.access(filename, os.R_OK):
          unreadable_files.append(filename)
    
    print 'Unreadable directories:\n{0}'.format('\n'.join(unreadable_dirs))
    print 'Unreadable files:\n{0}'.format('\n'.join(unreadable_files))
    

    Note: You could write your own recursive function that traverses the directory structure, but you’ll be basically duplicating os.walk functionality, so I don’t see the use case for glob.glob.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

/Users/smcho/Desktop/bracket/[10,20] directory has abc.txt, but when I run this Python code import glob import
Is there a better way to use glob.glob in python to get a list
I have insane big directory. I need to get filelist via python. In code
Python works on multiple platforms and can be used for desktop and web applications,
Python's convention is that variables are created by first assignment, and trying to read
I am learning Python (I have a C/C++ background). I need to write something
I just setup PortablePython on my system, so I can run python scripts from
I know how to mock methods in Python using flexmock, like flexmock(subprocess).should_receive('call').replace_with(my_func) How does
I want to create a list of those files in a directory which have
I've written a python function that scours a filesystem using a provided directory pattern,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.