Bash – What tool to use to draw file tree diagram

bashdiagramfilesystemsshell

Given a file tree – a directory with directories in it etc, how would you write a script to create a diagram of the file-tree as a graphic file that I can embed in a word processor document.
I prefer vector (SVG, EPS, EMF…) files.
The tool must run on Windows, but preferably cross-platform.
The tool may be commercial but preferably free.

Update 2012-02-20.
The question was related to a documentation sub project. I had to explan where files (in particular resources and configuration files) reside.
I ended up with using dos tree command. I both screen grabbed the result (for short folders) AND for longer folders I redirected to a text file, which I then edited. For example if a subfolder contained 20 similarly typed files that individually were not important to the point I was making, I left just two and replaced the rest with one … line. I then printed out the file to console again and screen grabbed it.
Before screen grabbing I had to modify foreground color to black and background color to white, to look better and save ink in a document should that be printed.

It is very surprising that there is no better tool for it. If I had time, I'd write a Visio Extension or may be some command line that produces SVG. SVG being HTML5 substandard, would even allow painless inclusion into online documentation.

Update 2017-10-17.
I am sorry that this question was removed as not belonging to SO. So I have re-worded it. I need a script – not a WYSIWYG tool. So any scripting language or library is ok. So it is a code – writing question, and I believe belongs to SO.

Best Solution

Copying and pasting from the MS-DOS tree command might also work for you. Examples:

tree

C:\Foobar>tree
C:.
├───FooScripts
├───barconfig
├───Baz
│   ├───BadBaz
│   └───Drop
...

tree /F

C:\Foobar>tree
C:.
├───FooScripts
│    foo.sh
├───barconfig
│    bar.xml
├───Baz
│   ├───BadBaz
│   │    badbaz.xml
│   └───Drop
...

tree /A

C:\Foobar>tree /A
C:.
+---FooScripts
+---barconfig
+---Baz
¦   +---BadBaz
¦   \---Drop
...

tree /F /A

C:\Foobar>tree /A
C:.
+---FooScripts
¦    foo.sh
+---barconfig
¦    bar.xml
+---Baz
¦   +---BadBaz
¦   ¦    badbaz.xml
¦   \---Drop
...

Syntax [source]

tree [drive:][path] [/F] [/A]

drive:\path — Drive and directory containing disk for display of directory structure, without listing files.

/F — Include all files living in every directory.

/A — Replace graphic characters used for linking lines with ext characters , instead of graphic characters. /a is used with code pages that do not support graphic characters and to send output to printers that do not properly interpret graphic characters.

Related Question