We use cookies to ensure you get the best experience on our website. Read our privacy policy

Skip to main content

Directory

File Tree Generator

The File Tree Generator is a powerful utility function that transforms nested object structures into visual file tree representations. Perfect for documentation, directory exploration, and project structure visualization.

The generator creates ASCII-style file trees that:

  • Check Circle

    Represent nested directory structures

  • Check Circle

    Use clear visual hierarchy

  • Check Circle

    Support unlimited nesting levels

  • Check Circle

    Maintain consistent formatting

import { generateFileTree } from '@/lib/shared/utils';
const tree = generateFileTree({
src: {
components: {
'Header.tsx': null,
'Footer.tsx': null,
},
styles: {
'global.css': null,
},
},
});

Output:

src/
├── components/
│ ├── Header.tsx
│ └── Footer.tsx
└── styles/
└── global.css
type FileTree = {
[key: string]: FileTree | null;
};
function generateFileTree(tree: FileTree, prefix: string = ''): string;
File Tree Generator Parameters
Parameter Type Default Description
tree FileTree Object representing directory structure
prefix string "" Internal parameter for recursion

When combined with the Expressive Code component, you can highlight specific parts of the tree:

src/
└── components
├── Button.tsx
├── old-component.tsx
└── new-component.tsx

Project documentation

Directory structure visualization

File system navigation

Code organization examples

Migration guides

Installation instructions

Limited Time Launch Sale

Start organizing and visualizing your project structure with our File Tree Generator. Get our AstroJS starter template now and enhance your documentation.

GET 60% OFF!
North Star Themes Logo

Subscribe to our newsletter

Get the latest AstroJS tips and tricks right to your inbox

Email: [email protected]

© 2025 North Star Themes

Web Kit Provided By North Star Themes