Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

7 Commits

Repository files navigation

📁 File Tree Extractor

PythonPlatformLicense

A Python utility that generates a visual directory tree structure of any folder, showing nested files and subfolders with proper indentation and connectors. Perfect for documenting project structures, creating visual inventories, or analyzing directory hierarchies.

Also check out - 📁File Name Extractor

✨ Features

  • Visual Tree Output — Generates a beautifully formatted directory tree with connectors (├──, └──, )
  • Smart Sorting — Directories are listed first, then files (alphabetically, case-insensitive)
  • Intelligent Truncation — The root folder shows all items (no limit); every subfolder is limited to 10 items with ... to indicate more contents
  • Interactive Directory Selection — Choose any folder via user input or scan the script's directory
  • Auto‑Numbered Output — Saves to tree_1.txt, tree_2.txt, etc. in the system temp folder — never overwrites
  • Auto‑Open — Automatically opens the generated file after saving
  • Full Unicode Support — Handles filenames in any language
  • Debug Mode — Optional detailed logging for troubleshooting
  • Error Handling — Graceful handling of permissions and encoding issues

📋 Requirements

  • Python 3.6 or higher
  • No external dependencies required (uses only standard library)

✏️ How it works

  • This script is simply meant to be used by doubling clicking on it and then pasting the directory after which the script shall auto open the tree list for you.

🎯 How It Works

1. Choose a Directory

The script prompts you to enter a directory path. You can enter:

  • Full path — C:\Users\YourName\Documents
  • Relative path — ..\..\OtherFolder
  • . — the current directory
  • Just press Enter — uses the script's own directory

2. Tree Generation

The script recursively scans the folder and builds a tree with:

  • Directories shown with a trailing /
  • Files shown without
  • Connectors showing parent-child relationships
  • Truncation at 10 items per folder with ...

3. Automatic Saving

The tree is automatically saved as a numbered file in your system's temporary folder:

  • Windows: C:\Users\YourName\AppData\Local\Temp\tree_1.txt
  • macOS: /var/folders/.../T/tree_1.txt
  • Linux: /tmp/tree_1.txt

4. Auto‑Open

The file automatically opens in your default text editor after saving.

📄 Sample Output

================================================================================
DIRECTORY TREE GENERATOR
================================================================================
Source Directory Scanned: C:\Users\YourName\Documents\MyProject
Generated on: 2025-01-15 14:32:18.451
Total lines in tree: 247
================================================================================
blind-image-restoration/
├── configs/
│ └── config.yaml
├── data/
│ ├── __pycache__/
│ │ ├── __init__.cpython-310.pyc
│ │ ├── dataset.cpython-310.pyc
│ │ └── degrade.cpython-310.pyc
│ ├── __init__.py
│ ├── dataset.py
│ ├── degrade.py
│ └── preprocess.py
├── evaluation/
│ ├── __pycache__/
│ │ ├── __init__.cpython-310.pyc
│ │ ├── embed_analysis.cpython-310.pyc
│ │ ├── metrics.cpython-310.pyc
│ │ └── ood_tests.cpython-310.pyc
│ ├── __init__.py
│ ├── embed_analysis.py
│ ├── infer.py
│ ├── metrics.py
│ └── ood_tests.py
├── logs/
│ ├── benchmark_results.csv
│ ├── benchmark_summary.csv
│ ├── eval_training_20260620_195512.log
│ ├── metrics.csv
│ ├── metrics_eval.csv
│ ├── metrics_eval_summary.csv
│ └── train_training_20260608_074856.log
├── models/
│ ├── __pycache__/
│ │ ├── __init__.cpython-310.pyc
│ │ ├── encoder.cpython-310.pyc
│ │ ├── losses.cpython-310.pyc
│ │ └── unet.cpython-310.pyc
│ ├── benchmark/
│ │ ├── __pycache__/
│ │ │ ├── hinet_arch.cpython-310.pyc
│ │ │ ├── network_swinir.cpython-310.pyc
│ │ │ └── restormer_arch.cpython-310.pyc
│ │ ├── pretrained_weights/
│ │ │ ├── 005_colorDN_DFWB_s128w8_SwinIR-M_noise15.pth
│ │ │ ├── 006_colorCAR_DFWB_s126w7_SwinIR-M_jpeg40.pth
│ │ │ ├── gaussian_color_denoising_blind.pth
│ │ │ └── HINet-SIDD-1x.pth
│ │ ├── hinet_arch.py
│ │ ├── network_swinir.py
│ │ └── restormer_arch.py
│ ├── __init__.py
│ ├── encoder.py
│ ├── losses.py
│ └── unet.py
├── results/
│ ├── checkpoints/
│ │ ├── best_model.pt
│ │ ├── ckpt_epoch100.pt
│ │ ├── ckpt_epoch125.pt
│ │ ├── ckpt_epoch150.pt
│ │ ├── ckpt_epoch175.pt
│ │ ├── ckpt_epoch200.pt
│ │ ├── ckpt_epoch225.pt
│ │ ├── ckpt_epoch25.pt
│ │ ├── ckpt_epoch250.pt
│ │ ├── ckpt_epoch50.pt
│ │ └── ...
│ ├── debug/
│ │ ├── CBSD68/
│ │ │ ├── blur_1.5/
│ │ │ │ ├── 0000_clean.png
│ │ │ │ ├── 0000_degraded.png
│ │ │ │ ├── 0000_restored.png
│ │ │ │ ├── 0001_clean.png
│ │ │ │ ├── 0001_degraded.png
│ │ │ │ ├── 0001_restored.png
│ │ │ │ ├── 0002_clean.png
│ │ │ │ ├── 0002_degraded.png
│ │ │ │ ├── 0002_restored.png
│ │ │ │ ├── 0003_clean.png
│ │ │ │ └── ...
│ │ │ ├── jpeg_20/
│ │ │ │ ├── 0000_clean.png
│ │ │ │ ├── 0000_degraded.png
│ │ │ │ ├── 0000_restored.png
│ │ │ │ ├── 0001_clean.png
│ │ │ │ ├── 0001_degraded.png
│ │ │ │ ├── 0001_restored.png
│ │ │ │ ├── 0002_clean.png
│ │ │ │ ├── 0002_degraded.png
│ │ │ │ ├── 0002_restored.png
│ │ │ │ ├── 0003_clean.png
│ │ │ │ └── ...
│ │ │ ├── jpeg_40/
│ │ │ │ ├── 0000_clean.png
│ │ │ │ ├── 0000_degraded.png
│ │ │ │ ├── 0000_restored.png
│ │ │ │ ├── 0001_clean.png
│ │ │ │ ├── 0001_degraded.png
│ │ │ │ ├── 0001_restored.png
│ │ │ │ ├── 0002_clean.png
│ │ │ │ ├── 0002_degraded.png
│ │ │ │ ├── 0002_restored.png
│ │ │ │ ├── 0003_clean.png
│ │ │ │ └── ...
│ │ │ ├── noise_15/
│ │ │ │ ├── 0000_clean.png
│ │ │ │ ├── 0000_degraded.png
│ │ │ │ ├── 0000_restored.png
│ │ │ │ ├── 0001_clean.png
│ │ │ │ ├── 0001_degraded.png
│ │ │ │ ├── 0001_restored.png
│ │ │ │ ├── 0002_clean.png
│ │ │ │ ├── 0002_degraded.png
│ │ │ │ ├── 0002_restored.png
│ │ │ │ ├── 0003_clean.png
│ │ │ │ └── ...
│ │ │ └── noise_25/
│ │ │ ├── 0000_clean.png
│ │ │ ├── 0000_degraded.png
│ │ │ ├── 0000_restored.png
│ │ │ ├── 0001_clean.png
│ │ │ ├── 0001_degraded.png
│ │ │ ├── 0001_restored.png
│ │ │ ├── 0002_clean.png
│ │ │ ├── 0002_degraded.png
│ │ │ ├── 0002_restored.png
│ │ │ ├── 0003_clean.png
│ │ │ └── ...
│ │ └── Kodak24/
│ │ ├── blur_1.5/
│ │ │ ├── kodim01_clean.png
│ │ │ ├── kodim01_degraded.png
│ │ │ ├── kodim01_restored.png
│ │ │ ├── kodim02_clean.png
│ │ │ ├── kodim02_degraded.png
│ │ │ ├── kodim02_restored.png
│ │ │ ├── kodim03_clean.png
│ │ │ ├── kodim03_degraded.png
│ │ │ ├── kodim03_restored.png
│ │ │ ├── kodim04_clean.png
│ │ │ └── ...
│ │ ├── jpeg_20/
│ │ │ ├── kodim01_clean.png
│ │ │ ├── kodim01_degraded.png
│ │ │ ├── kodim01_restored.png
│ │ │ ├── kodim02_clean.png
│ │ │ ├── kodim02_degraded.png
│ │ │ ├── kodim02_restored.png
│ │ │ ├── kodim03_clean.png
│ │ │ ├── kodim03_degraded.png
│ │ │ ├── kodim03_restored.png
│ │ │ ├── kodim04_clean.png
│ │ │ └── ...
│ │ ├── jpeg_40/
│ │ │ ├── kodim01_clean.png
│ │ │ ├── kodim01_degraded.png
│ │ │ ├── kodim01_restored.png
│ │ │ ├── kodim02_clean.png
│ │ │ ├── kodim02_degraded.png
│ │ │ ├── kodim02_restored.png
│ │ │ ├── kodim03_clean.png
│ │ │ ├── kodim03_degraded.png
│ │ │ ├── kodim03_restored.png
│ │ │ ├── kodim04_clean.png
│ │ │ └── ...
│ │ ├── noise_15/
│ │ │ ├── kodim01_clean.png
│ │ │ ├── kodim01_degraded.png
│ │ │ ├── kodim01_restored.png
│ │ │ ├── kodim02_clean.png
│ │ │ ├── kodim02_degraded.png
│ │ │ ├── kodim02_restored.png
│ │ │ ├── kodim03_clean.png
│ │ │ ├── kodim03_degraded.png
│ │ │ ├── kodim03_restored.png
│ │ │ ├── kodim04_clean.png
│ │ │ └── ...
│ │ └── noise_25/
│ │ ├── kodim01_clean.png
│ │ ├── kodim01_degraded.png
│ │ ├── kodim01_restored.png
│ │ ├── kodim02_clean.png
│ │ ├── kodim02_degraded.png
│ │ ├── kodim02_restored.png
│ │ ├── kodim03_clean.png
│ │ ├── kodim03_degraded.png
│ │ ├── kodim03_restored.png
│ │ ├── kodim04_clean.png
│ │ └── ...
│ └── embed_analysis/
│ └── tsne.png
├── training/
│ ├── __pycache__/
│ │ ├── __init__.cpython-310.pyc
│ │ ├── train.cpython-310.pyc
│ │ └── validate.cpython-310.pyc
│ ├── __init__.py
│ ├── train.py
│ └── validate.py
├── utils/
│ ├── __pycache__/
│ │ ├── __init__.cpython-310.pyc
│ │ ├── ema.cpython-310.pyc
│ │ ├── logger.cpython-310.pyc
│ │ ├── sampling.cpython-310.pyc
│ │ └── schedule.cpython-310.pyc
│ ├── __init__.py
│ ├── ema.py
│ ├── logger.py
│ ├── sampling.py
│ └── schedule.py
├── {configs,data,models,training,evaluation,utils,logs,results/
│ └── checkpoints}/
├── benchmark.py
└── main.py
└── requirements.txt

⚙️ Configuration

Debug Mode

To enable debug output (timestamps and detailed logs), set DEBUG = True at the top of the script:

# Enable debug mode (set to False to disable debug output)DEBUG=True

Max Items Per Folder

To change how many items are shown per directory before truncating with ..., modify the max_items parameter in the generate_tree() call:

# Line near the bottom of main()children_lines=generate_tree(target_directory, prefix="", is_last=True, max_items=10, depth=0)

🛠️ Troubleshooting

IssueSolution
"Permission Denied"Run the script with appropriate permissions for the target directory
No output file createdCheck write permissions for your system's temp folder
File doesn't auto-openThe script will show you the file path — you can open it manually
Unicode characters display as ?The script uses UTF-8 encoding; ensure your terminal supports it
Directory contains thousands of filesThe max_items limit (10) prevents excessively large output — adjust if needed

🆚 File Tree Extractor vs. File Name Extractor

FeatureTree ExtractorName Extractor
OutputVisual directory treeFlat list of filenames
StructureShows nesting & hierarchyAll files in one list
Directory infoShows directories + filesFiles only
Best forProject documentation, visual overviewFile inventories, backup lists

📝 Notes

  • The script uses the system's temporary folder to save output files (never overwrites — numbered sequentially)
  • Files are sorted directories first, then files for cleaner reading
  • The ... ellipsis appears when a folder contains more than 10 items
  • Unicode filenames are fully supported (Japanese, Arabic, Chinese, etc.)

About

A Python utility that generates a visual directory tree structure of any folder, showing nested files and subfolders with proper indentation and connectors. Perfect for documenting project structures, creating visual inventories, or analyzing directory hierarchies.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages