|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
vb.net 2008 display and print directory/subdirectoriesI 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 w wrote:
> I am looking for suggestions on how to implement a view of (If you're looking for something quick and dirty, you could capture the > 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. output of the "tree" command from a command prompt.) -- Andrew 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 > On 20/04/2010 17:52, w wrote:
> Yeah, it needs to be "cleaner" than that. I created a batch file that You're looking at a Recursive routine that will scan a given directory > lists the directories and subdirectories and then sends it to the > default printer, but it is to raw and unformatted. 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. 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.
Foreign Currency Exchange Rates Web service
Get email with Visual Basic 2008 Draw an arrow on a line How to read a Stream into an XElement how to use a common class in different projects Importing data from web site search for a string or part of a string in another string algoritm special permutation Where is My.Settings? Good APIs for Music Lyrics |
|||||||||||||||||||||||