How can I export a directory structure in Windows?

Assuming your directory tree is of reasonable size, you could also use the built in tree command, which produces a rather pretty looking directory tree. Unfortunately this prettiness is difficult to get working outside of a cmd instance, so you'll probably want to tell it to just use ascii characters with the /A switch.

Example:

From a small multi-level structure

+---A
|   +---A
|   \---B
+---B
|   \---A
|       \---A
\---C

You can then redirect this to a file using a command like:

tree /A ["directory path"] > tree.txt

Where the directory path is optional, but useful if you want to tree something which isn't the current working directory.


If you want to use powershell the code is very simple and the output is nice.

Code:

Get-ChildItem | tree

With

Get-ChildItem | tree > foo.txt

you can pipe the output to a Textfile.

Example Output:

Auflistung der Ordnerpfade für Volume System
Volumeseriennummer : 48E9-F43B
C:.
├───Contacts
├───Desktop
├───Downloads
│   └───Evernote Import
├───Dropbox
│   ├───Apps
│   │   └───iftttcom
│   │       └───getpocketpdf
│   ├───Backup
│   ├───Camera Uploads
│   ├───Development

You can also put the results directly into the clipboard (in Vista+):

tree | clip