How can I export a directory structure?

Photo by Markus Spiske on Unsplash

Exporting a directory structure in windows is not straightforward and is required for many purposes.  There are various ways of achieving this task. but a few handy and no installation commands to generate different types of export are listed below.

Using Command line

Assuming your directory tree is of reasonable size, you could also use the built-in commandtree, which produces a rather pretty looking directory tree.

tree "<directory path>" > directory_structure.txt

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 switch/A.

|   +---A
|   \---B
|   \---A
|       \---A
tree /A "<directory path>" > directory_tree.txt

Using Powershell

A basic usage

Get-ChildItem | tree > foo.txt

Below is an example to export the directory structure with specific headers like name, FullName, timestamp etc. A full list of headers/properties is found HERE

Get-ChildItem -Recurse 'D:\New Folder' | Select-Object -Property FullName,name,timestamp | Export-Csv directory_structure.csv

List all the JPEG pictures in a folder and its sub-folders.

dir /s *.jpg > files_jpg.txt

A simple detailed information with Filename and directory path.

dir /s/b *.jpg > files_simpleformat_jpg.txt