Home All Groups Group Topic Archive Search About

vb.net 2008 display and print directory/subdirectories

Author
20 Apr 2010 3:49 PM
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

Author
20 Apr 2010 4:13 PM
Andrew Morton
w wrote:
> 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.)

--
Andrew
Author
20 Apr 2010 4:52 PM
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.

Show quoteHide quote
"Andrew Morton" <a**@in-press.co.uk.invalid> wrote in message
news:83625cFlisU1@mid.individual.net...
>w wrote:
>> 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.)
>
> --
> Andrew
>
Author
21 Apr 2010 11:01 AM
Phill W.
On 20/04/2010 17:52, w wrote:
> 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.
Author
21 Apr 2010 3:19 PM
w
Thanks for the input.  I could work on saving the information to a text file
or output as html.

Show quoteHide quote
"Phill W." <p-.-a-.-w-a-r-d-@-o-p-e-n-.-a-c-.-u-k> wrote in message
news:hqmlus$abu$1@south.jnrs.ja.net...
> On 20/04/2010 17:52, w wrote:
>> 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.