The fastest way to create a directory tree in CMD on Windows is to call mkdir with the full nested path on one line, for example mkdir src\components\ui src\lib utils, which creates every parent folder in the chain and any sibling directories listed in the same command. The Windows command prompt has no built-in tree writer that draws the picture for you, so the two practical tasks are usually conflated: you must first build the structure on disk, and then you must render it as readable text for documentation. Both jobs are solvable from CMD alone, and both become easier when you stop typing paths by hand and start generating them from a flat list.

how to create directory tree in cmd
how to create directory tree in cmd

What "creating a directory tree in CMD" actually means

When developers search for this phrase, they usually want one of three things, and the right answer differs for each. The first is the literal creation of nested folders on disk, which is a write operation handled by mkdir (or its alias md). The second is the rendering of an existing folder structure as an ASCII diagram, which is what the tree command and its /F and /A switches produce. The third is the production of a tree-shaped text block to paste into a README, design doc, or pull request — a job CMD cannot do on its own, but that a path-list-to-tree converter handles cleanly.

Because CMD cannot both build and pretty-print a tree in a single round trip, most workflows split the work: a script or hand-typed mkdir line creates the directories, and a separate step produces the text diagram. Recognising which of those three jobs you actually need is the difference between a 10-second fix and a 10-minute detour.

Building a nested folder tree with mkdir

Open CMD, navigate to the parent folder where you want the tree to live, and use mkdir with a backslash-joined path. Windows mkdir creates every intermediate directory that does not yet exist, so one command is enough for a deep branch.

  1. Press Win + R, type cmd, and press Enter.
  2. Move to the target parent: cd C:\Projects\my-app.
  3. Create a full branch in one go: mkdir src\components\ui src\lib src\styles public\assets public\docs.
  4. Verify the result with dir or tree from the same folder.
  5. For reusable scaffolding, paste the commands into a setup.bat file and run it from CMD with setup.bat.

The key detail is that CMD's mkdir accepts multiple space-separated paths in a single invocation, which lets you build an entire sibling tree in one line. If you prefer forward slashes, Windows accepts those too for the filesystem, though CMD's own help text and most batch files traditionally use backslashes.

Rendering a tree from CMD with the tree command

Once folders exist, the built-in tree command draws them. By default it uses extended ASCII line-drawing characters that look fine in a modern Windows Terminal but can render as garbage in older cmd.exe windows or when pasted into a web page. The fix is tree /A, which swaps the box-drawing characters for plain +, |, and ` characters.

CommandOutput styleBest for
treeExtended ASCII (box-drawing)Modern Windows Terminal viewing
tree /APure ASCII charactersPasting into READMEs, issues, code review
tree /FFiles and foldersInspecting a full project layout
tree /F /A > tree.txtSaved to fileSharing the layout in a commit or attachment

The redirection trick is the most reliable CMD-only path to a copy-ready block: tree /F /A > tree.txt writes a portable ASCII diagram into the working directory, and you can open it in Notepad or paste it anywhere. For very deep trees you may want to add more into the pipeline so the terminal pauses per page, but the redirected file already holds the complete output.

Generating a tree from a flat path list

Sometimes you do not have the folders yet — you have a list of target paths in a spec, ticket, or design doc, and you need to turn that list into a tree-shaped text block before any directories exist. CMD cannot read a text file of paths and emit a tree, but the Directory Tree Generator is built for exactly this workflow. You paste one relative path per line, choose forward slash or backslash input, pick Unicode or ASCII output, and the tool produces a deterministic tree with a node count and a copy-ready block.

  1. Collect your paths in a plain text editor, one path per line, using a consistent separator style.
  2. Open the Directory Tree Generator in your browser.
  3. Paste the list into the input area and select forward slash or backslash depending on what you typed.
  4. Choose Unicode for Windows Terminal and Markdown viewers, or ASCII for plain text files and older tools.
  5. Click generate, review the node count and full tree, then copy the block into your README, issue, or review.

The deterministic part matters: given the same input and the same character set, the output is identical, so the same block regenerates byte-for-byte every time. That makes it safe to commit the rendered tree alongside the source list, or to regenerate the diagram whenever the path list changes.

Which approach to use for which job

CMD is the right tool when you are at the keyboard and need folders on disk right now, and the rendered diagram is a secondary concern. The Directory Tree Generator is the right tool when you are writing documentation and need a consistent, portable tree block without touching the filesystem. Combining them is common: paste a spec into the generator, copy the rendered tree into a setup.bat comment, and run the mkdir lines below the comment to materialise the structure.

TaskBest CMD-native approachWhen to switch to a generator
Scaffold a new project locallymkdir with full nested pathsRarely — CMD is faster here
Print a tree of existing filestree /F /A > tree.txtOnly if you need Unicode art or remote paths
Build a tree diagram for a READMEtree /A then editWhen you need consistent style across repos
Render a tree from a spec or ticketNot possible in CMD aloneAlways use the Directory Tree Generator

For diff-friendly documentation, plain ASCII wins almost every time because Unicode box characters sometimes survive poorly through copy-paste, email clients, and certain Markdown renderers. Save Unicode output for viewers you control, such as a project wiki that supports HTML or a Windows Terminal session.

Common pitfalls when building trees in CMD

The most frequent mistake is quoting an entire path with internal spaces, which breaks the command into one argument and confuses mkdir. Wrap each spaced segment in its own quotes: mkdir "src\my components\ui". Another trap is assuming forward and backward slashes behave identically in batch files — they usually do for mkdir, but other commands such as for /f and if exist are pickier, so pick a separator and stay consistent.

Quoted paths also matter when piping tree output, because a path containing an & character can be interpreted as a command separator by CMD. If you must handle such paths, redirect to a file first and then read the file. For deeper safety, run CMD with /D to disable AutoRun and keep the session predictable across machines.

Putting the two workflows together

A repeatable pattern is to keep a paths.txt file at the project root that lists every target path, regenerate the rendered tree block from it before each release, and run a small batch script that reads the same list to create missing folders. The Directory Tree Generator gives you the rendered side; a 10-line batch file reading paths.txt line by line with for /f gives you the disk side. Together they keep documentation and reality in sync without manual typing.

If you work on JSON-heavy projects, you may also want to validate any config files alongside the scaffold using a tool like the JSON Validator, and if you produce Markdown trees often it helps to keep the ASCII code reference handy so you know exactly which characters survive copy-paste. For comparing tree changes between commits, the Diff Checker is a quick way to spot accidental folder moves before they ship.

For a deeper look, see Create a Dummy File in CMD with Exact Size and Content.

For a deeper look, see How to Create Flexbox in CSS: A Practical Walkthrough.