DisplayTree.ps1
📜 is a PowerShell script that generates a tree-like 🌳 view of a directory's structure, displaying it in the terminal 🖥️ and saving it to a text file 📝. The output text file is saved in the root 🏠 folder of the directory it was run from, uniquely named 🏷️ with an ISO Date-Time ⏰ prefix for easy identification.
📄 Example output and typical example output filename: 20231015T091656_DisplayTree.ps1
🗂️
Your_Root_Directory
|--- build
|--- static
|--- css
|--- main.css
|--- js
|--- main.js
|--- index.html
|--- public
|--- favicon.ico
|--- index.html
|--- src
|--- components
|--- Header
|--- Header.css
|--- Header.jsx
|--- containers
|--- App
|--- App.css
|--- App.js
|--- utils
|--- constants.js
|--- package.json
|--- README.md
The DisplayTree.ps1
is a PowerShell script designed to display a tree-like 🌳 directory structure of a given directory. It is specially tailored for projects and can be run from any location 📍. The script displays both directories 📂 and files 📄 and also writes this structure to a text file 📝 with a unique ISO Date-Time 🕒 prefix. It includes an exception to show the node_modules
directory 📦 without diving into its internal structure. Example output file will be saved in the directory it's run in: Example: 20231015T091656_DisplayTree.ps1
- 🪟 Windows 11 or compatible Windows version
- 🖥 PowerShell 5.1 or higher
- 🌳 Displays a tree-like structure of directories and files
- 📝 Outputs the structure to a uniquely named text file with an ISO Date-Time 🕒 prefix
- 🌐 Can be run from any directory
- 📦 Special handling for
node_modules
directory to prevent excessive nesting
- 💾 Save
DisplayTree.ps1
in a directory of your choice. - (Optional) 🛠 Add the directory to your system's PATH or create a PowerShell alias for easy access.
- 💻 Open the PowerShell terminal.
- 📂 Navigate to the directory you wish to scan.
- 🎬 Run
.\DisplayTree.ps1
or use the alias if you set one up.
The script will display the directory structure in the terminal and save it to a text file 📝 in the current directory.
👩💻 To be able to call DisplayTree.ps1
from any directory, you have several options:
-
📁 Move Script: Move
DisplayTree.ps1
to a directory that is easy to remember and access. For example, you could create aScripts
folder in your user directory or yourC:\
drive. -
🌐 Add to PATH: Add that directory to your system's
PATH
environment variable. -
🔄 Open a New PowerShell Session: After this, you can call
DisplayTree.ps1
from any directory.- ❗ Note: Incorrectly modifying the
PATH
variable can lead to issues. Make sure you know what you're doing before modifying it.
- ❗ Note: Incorrectly modifying the
-
📝 Open Your PowerShell Profile: Enter
notepad $PROFILE
in a PowerShell window. This will open your PowerShell profile in Notepad. You'll be prompted to create one if the profile doesn't exist. -
👍 Add Alias: Add the following line to your PowerShell profile, replacing
C:\path\to\DisplayTree.ps1
with the full path to your script:Set-Alias displaytree "C:\path\to\DisplayTree.ps1"
-
💾 Save and Close Notepad: Save the changes and close Notepad.
-
🔄 Reload Profile or Restart PowerShell: For the changes to take effect, either reload your profile with
. $PROFILE
or close and reopen PowerShell.
After doing this, you should be able to use the command displaytree
in PowerShell, no matter your current directory, to run your DisplayTree.ps1
script.
-
📍 This doesn't allow you to run it from "anywhere," but you can always run the script using its fully qualified path:
& "C:\path\to\DisplayTree.ps1"
Any of these methods will allow you to execute the script from any directory. Choose the one that best suits your needs 🌟.