earnestt1234 / seedir

A Python package for creating, editing, and reading folder tree diagrams
MIT License
122 stars 9 forks source link

[Feature requests] How to ignore error like permission denied. #28

Closed ramwin closed 4 months ago

ramwin commented 9 months ago

compare to tree image

image

How about add a parameter like errors="ignore"?

earnestt1234 commented 9 months ago

I think this is a good suggestion. I imagine it will involve wrapping the call to list the children of a folder in a try/except block. I will look into making this change

earnestt1234 commented 4 months ago

This functionality has been added in version 0.5.0. Relevant changes are in 61de607f1e740424e9ca2070dd705cfaaac02d15 and 83a6b07c2d95ee1908addd278f19522d0edd4cdb.

Two new parameters associated with this change are acceptable_listdir_errors (what errors are okay to be ignored) and denied_string (what string token to add to folders that can't be accessed).

Example:

>>> import seedir
>>> seedir.seedir('/Users/admin/', depthlimit=2)
admin/
├─Music/ [ACCESS DENIED]
├─.Box_UIServer
├─.CFUserTextEncoding
├─Pictures/ [ACCESS DENIED]
├─Desktop/ [ACCESS DENIED]
├─Library/ [ACCESS DENIED]
├─Public/
│ ├─.localized
│ └─Drop Box/ [ACCESS DENIED]
├─Movies/ [ACCESS DENIED]
├─.Box_EngineServer
├─Documents/ [ACCESS DENIED]
└─Downloads/ [ACCESS DENIED]