Directory Tree Package
About
Want to Display your Project / Current Working Directory as a Neat Tree? No Worries!
Directory Tree is a simple python utility package that displays out the Tree Structure of a User Defined Directory.
Currently Available for All Platforms.
Installation
Run the Following Command on your Terminal to Install directory_tree:
1 . Installing the Package using pip:
pip install directory_tree
OR
pip3 install directory_tree
2 . Cloning the Repository:
git clone https://github.com/rahulbordoloi/Directory-Tree/
cd Directory-Tree
pip install -e .
You can use either of the above methods to install directory_tree.
Usage
Function Signature
DisplayTree(
dirPath: str='',
stringRep: bool=False,
header: bool=False,
maxDepth: float=float('inf'),
showHidden: bool=False,
ignoreList: List[str]=None,
onlyFiles: bool=False,
onlyDirs: bool=False,
sortBy: int=0
) -> Union[str, None]:
Arguments Description
| Parameters | CLI Parameters | Description |
|---|---|---|
| dirPath | directory |
Root Path of Operation. By Default, Refers to the Current Working Directory. |
| stringRep | N/A | Boolean Flag for Direct Console Output or a String Return of the Same. By Default, It Gives out Console Output. |
| header | --header |
Boolean Flag for Displaying [OS & Directory Path] Info in the Console. Not Applicable if stringRep=True. |
| maxDepth | -L, --max-depth |
Max Depth of the Directory Tree. By Default, It goes upto the Deepest Directory/File. |
| showHidden | -a, --show-hidden |
Boolean Flag for Returning/Displaying Hidden Files/Directories if Value Set to True. |
| ignoreList | -I, --ignore-list |
List of File and Directory Names or Patterns to Ignore. |
| onlyFiles | -f, --only-files |
Boolean Flag to Display Only Files |
| onlyDirs | -d, --only-dirs |
Boolean Flag to Display Only Directories |
| sortBy | --sort-by |
Sorting order. Possible Options: 0 - Default, 1 - Files First, 2 - Directories First |
| raiseException | --raise-exception |
Boolean Flag to Raise Exception. By Default, It Doesn't Raise Exception |
| printErrorTraceback | --print-error-traceback |
Boolean Flag to Print Error Traceback. By Default, It Doesn't Print Error Traceback |
Command Line
- Treating the Cloned Directory as Executable -
(Works if you've cloning privileges but not of installation. You can clone the repo, go to its root and run the below)
python directory_tree
OR
python -m directory_tree
Use the inline help for command-line options:
python directory_tree --help
- Treating the Package as Module -
(You would need to install (pip) the Python Package in your system for the below to work)
directory_tree
Use the inline help for command-line options:
directory_tree --help
In Code
Example Script to Print out the Tree Structure of a User-Defined Directory directoryPath!
# Importing Libraries
from directory_tree import DisplayTree
# Main Method
if __name__ == '__main__':
DisplayTree(directoryPath)
- Here by default, the
directoryPathis the current working directory (CWD) unless specified by the user.
Output Examples
Sample Directory Tree -
NOTE - Here, letseee.txt (File) and Directory 4/ (Directory) are HIDDEN in Nature.
- For Current Working Directory with Argument [Header Info =
False]
from directory_tree import DisplayTree
DisplayTree(header=True)
- For User Specified Directory with Arguments [String Representation =
True, Show Hidden Entities =True]
from directory_tree import DisplayTree
customPath: str = 'Users/rahulbordoloi/Work/Python Packages Maintainence/Directory-Tree/Test/Main Directory'
stringRepresentation: str = DisplayTree(customPath, stringRep=True, showHidden=True)
print(stringRepresentation)
- For Current Working Directory with Argument [Max Depth =
2]
from directory_tree import DisplayTree
DisplayTree(maxDepth=2)
Developing Directory Tree
To install directory_tree, along with the tools you need to develop and run tests, use any of the following commands in your virtualenv:
pip install -e .[dev]
OR
pip install -e ".[dev]"
Deprecation Notice
The display_tree function is deprecated and will be removed in a future release. Please use DisplayTree instead. The end-of-life date for display_tree is December 31, 2024.
Parameters Mapping Table -
| New Parameters | Deprecated Parameters |
|---|---|
| dirPath | dir_path |
| stringRep | string_rep |
| maxDepth | max_depth |
| showHidden | show_hidden |
| ignoreList | ignore_list |
| onlyFiles | only_files |
| onlyDirs | only_dirs |
| sortBy | sort_by |
| raiseException | raise_exception |
| printErrorTraceback | print_error_traceback |
Security & Probable Bugs
Directory Treeuses recursion. It will raise aRecursionErroron really deep directory trees.- As the tree is lazily evaluated, it should behave well on really wide directory trees. Immediate children of a given directory are not lazily evaluated, though. It would be prompted to the last.
- If you're a Windows user, it is always advised to use
\\instead of\in the address as using\might catchup escape sequences and corrupt the address string.
Contact Author
Name : Rahul Bordoloi
Website : https://rahulbordoloi.me
Email : rahulbordoloi24@gmail.com
Made with ♥ in Python!
Metadata
Release files for directory-tree 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| directory_tree-1.0.0.tar.gz | 28.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| directory_tree-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 51.3 kB
Release files / directory_tree-1.0.0.tar.gz
| Download URL | directory_tree-1.0.0.tar.gz |
|---|---|
| Size | 28.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d65b404d7e561db62e6321f36c612cd12da2e9fbe5cbae98da73ce14c0ec910d
|
|
BLAKE2b-256 checksum How to use checksums |
ba487dbb436a54e0b727ba81ccb1bcf7875e875f826dcf43e01b9ad52726b179
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.12.0
|
Release files / directory_tree-1.0.0-py3-none-any.whl
| Download URL | directory_tree-1.0.0-py3-none-any.whl |
|---|---|
| Size | 23.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2484ba5e9d35e087703913cc85e920f08b9b942859b9f5a0eae24699d3364734
|
|
BLAKE2b-256 checksum How to use checksums |
4efb047673ca107e735c0dd9e03811a6f0c8c22ed72d6db596134399580c80c5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.12.0
|
Security for directory-tree 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.