directory-structure
Print a directory tree structure in your Python code.
Download
You can simply:
pip install directory-structure
Or you can also:
- Clone the repository to your local machine.
- Enter the directory.
- Download necessary modules/libraries.
git clone https://github.com/gabrielstork/directory-structure.git
cd directory-structure
pip install -r requirements.txt
Examples
from directory_structure import Tree
Using absolute path as an argument.
path = Tree('C:/Users/User/Desktop/directory-structure', absolute=True)
print(path)
π C:
|_π Users
|_π User
|_π Desktop
|_π directory-structure
|_π .git
|_π directory_structure
|_π .gitignore
|_π LICENSE
|_π pyproject.toml
|_π README.md
|_π requirements.txt
|_π setup.py
path = Tree('C:/Users/User/Desktop/directory-structure', absolute=False)
print(path)
π directory-structure
|_π .git
|_π directory_structure
|_π .gitignore
|_π LICENSE
|_π pyproject.toml
|_π README.md
|_π requirements.txt
|_π setup.py
Accessing a folder in current working directory.
path = Tree('./directory_structure', absolute=True)
print(path)
π C:
|_π Users
|_π User
|_π Desktop
|_π directory-structure
|_π directory_structure
|_π tree.py
|_π __init__.py
path = Tree('./directory_structure', absolute=False)
print(path)
π directory_structure
|_π tree.py
|_π __init__.py
Getting all from the directory where your current working directory is.
path = Tree('../', absolute=True)
print(path)
π C:
|_π Users
|_π User
|_π Desktop
|_π directory-structure
|_π Discord.lnk
|_π Spotify.lnk
|_π Steam.lnk
|_π Telegram.lnk
|_π Visual Studio Code.lnk
|_π WhatsApp.lnk
path = Tree('../', absolute=False)
print(path)
π Desktop
|_π directory-structure
|_π Discord.lnk
|_π Spotify.lnk
|_π Steam.lnk
|_π Telegram.lnk
|_π Visual Studio Code.lnk
|_π WhatsApp.lnk