Last Updated on February 14, 2022 by shibatau
I. What will you do?
Let’s print a directory tree structure with python. In addition. you will learn how to copy a full path in Kitty terminal emulator.
II. Copy the full path of a directory to the clipboard in Kitty
I’m using Fish shell and Kitty on Mac. So I run the following command in the terminal to copy the full path of the Desktop directory:
realpath Desktop |kitty +kitten clipboard
III. Install directory-structure
I’ll install directory-structure on a virtual environment created with anaconda.
1. Activating a virtual environment
I have already created a virtual environment with conda commands on Mac. So I have run the command:
conda activate MYENVIRONMENT
pip install directory-structure
IV. Print a directory tree structure
Run the following code to enter the Python interactive console:
Run the following Python codes. Here you can insert the path copied to the clipboard between the quotation marks. But you will get an error if you paste the path before you have typed the other parts because Ctrl +Shift + v include the run command.
from directory_structure import Tree path = Tree('/Users/YOURNAME/Desktop', absolute=True) print(path)