vb.net 2008 display and print directory/subdirectories

W

w

I am looking for suggestions on how to implement a view of
directories/subdirectories and then output the results to a printer.
similar to a table of contents.

I have been looking at the system.io.directories, and it makes sense how to
get just the directories of a given path, but I am stuck on how to determine
if the directory has sub-directories and then loop through them accordingly.
Probably something recursive, but if you have ideas that would be great.
Seams like I am reinventing the wheel here, but the desired goal of an
output to a printer just isn't available.

WB
 
A

Andrew Morton

w said:
I am looking for suggestions on how to implement a view of
directories/subdirectories and then output the results to a printer.
similar to a table of contents.

I have been looking at the system.io.directories, and it makes sense
how to get just the directories of a given path, but I am stuck on
how to determine if the directory has sub-directories and then loop
through them accordingly. Probably something recursive, but if you
have ideas that would be great. Seams like I am reinventing the wheel
here, but the desired goal of an output to a printer just isn't
available.

(If you're looking for something quick and dirty, you could capture the
output of the "tree" command from a command prompt.)
 
W

w

Yeah, it needs to be "cleaner" than that. I created a batch file that lists
the directories and subdirectories and then sends it to the default printer,
but it is to raw and unformatted.
 
P

Phill W.

Yeah, it needs to be "cleaner" than that. I created a batch file that
lists the directories and subdirectories and then sends it to the
default printer, but it is to raw and unformatted.

You're looking at a Recursive routine that will scan a given directory
and then call itself for each of its subdirectories, something like:

Imports System.IO

Sub ScanR( _
byval sPath as string _
, byval iLevel as Integer _
, byval sw as StreamWriter _
)

For i as integer = 1 to iLevel
sw.Write( " " )
Next

sw.WriteLine( Path.GetFilename( sPath )

For Each sSubDir as String _
in Directory.GetDirectories( sPath, "*.*" )

Me.ScanR( sSubDir, iLevel + 1, sw )
Next

End Sub

.... then ...

ScanR( "C:\Windows", 0, sw )

Be warned; if you're running this on anything but the most /trivial/ of
directory structures, such "raw" output will very quickly become
unreadable, running to pages and pages of stuff (even worse if the
nesting gets /so/ deep that the output starts to word-wrap!).

HTH,
Phill W.
 
W

w

Thanks for the input. I could work on saving the information to a text file
or output as html.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top