Python: Print a directory tree structures, directory-structure, kitty

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

2.Installing tree-structure

Install tree-structure:

pip install directory-structure

IV. Print a directory tree structure

Run the following code to enter the Python interactive console:

Python

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)

About shibatau

I was born and grown up in Kyoto. I studied western philosophy at the University and specialized in analytic philosophy, especially Ludwig Wittgenstein at the postgraduate school. I'm interested in new technology, especially machine learning and have been learning R language for two years and began to learn Python last summer. Listening toParamore, Sia, Amazarashi and MIyuki Nakajima. Favorite movies I've recently seen: "FREEHELD". Favorite actors and actresses: Anthony Hopkins, Denzel Washington, Ellen Page, Meryl Streep, Mia Wasikowska and Robert DeNiro. Favorite books: Fyodor Mikhailovich Dostoyevsky, "The Karamazov Brothers", Shinran, "Lamentations of Divergences". Favorite phrase: Salvation by Faith. Twitter: @shibatau

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.