Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Easy way to print a tree view...

Status
Not open for further replies.

Turpis

Programmer
Apr 16, 2002
151
I need an easy way to print a tree view. The problem is that I am not well versed in VB6. I have built a form with a drivelistbox and a folderlistbox. I would like to be able to just click to the folder that contains files and subfolders then hit my "print tree" button and wham-o a tree /f prints using that current folder.

I tried using:
dim sh
sh=shell("tree /f filList.Path")

But of course this doesn't work. tree /f is exactly what I want to do. I have to print these tree views for our computer unsaavy contract's manager about 5-12 times a week, would be nice if I could just put together something where he could just point and click and print. Any ideas would be appreciated.

Charles
Walden's Machine, Inc.
Quality Assurance/Office Developer
 
Charles,

Here is a quick and dirty solution that could help out.

But using the FileSystemObject, you can select a folder, then create a text file of all of the file names in that folder. Nothing too fancy. You can change it and have an Input Box request the folder name. NOTE: There is not much error checking in this example...

Hope it helps out.

Jim Mc

Option Explicit
'**********************************************************
' This code was created by Jim McNaughton
' Date: 2003-06-30
'
'**********************************************************
' The purpose of this code is to emulate a Tree Print
' program that I can no longer get on the Internet.
'**********************************************************
Dim objFSO As FileSystemObject
Dim objFolder As Folder
Dim objFiles As Files
Dim objFile As File
Dim objTS As TextStream

Dim sLogFileName As String
Dim sFolderName As String

Dim HoldTime As Date
Dim ElapsedTime As Date
Dim intFiles As Integer


Sub Main()

HoldTime = Now() ' start process

'**********************************************************
' Figure out a way to pass the file name locations to
' this program so that they are not hard-coded...
' Use an InputBox to get a folder name from user?
'**********************************************************
sFolderName = "C:\Program Files\Foldername"

Set objFSO = New FileSystemObject

'**********************************************************
' Figure out a way to pass the file name locations to
' this program so that they are not hard-coded...
' Use an InputBox to get a log file name from user?
'**********************************************************
sLogFileName = "C:\Temp\TreePrint-" & Format(Now(), "yyyy") & Format(Now(), "mm") & Format(Now(), "dd") & ".txt"

Set objTS = objFSO.CreateTextFile(sLogFileName, True)

WriteToLog ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
WriteToLog ("Process started at " & Now())
WriteToLog ("Folder name : " & sFolderName)
WriteToLog ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
WriteToLog (" ")

Set objFolder = objFSO.GetFolder(sFolderName)

Set objFiles = objFolder.Files

For Each objFile In objFiles

WriteToLog (objFile.Name)
intFiles = intFiles + 1

Next objFile

ElapsedTime = Now() - HoldTime ' end of process

WriteToLog (" ")
WriteToLog ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
WriteToLog ("Files: " & intFiles)
WriteToLog ("Process ended at " & Now())
WriteToLog ("Total elapsed time for process - " & Format(ElapsedTime, "Hh:Nn:Ss"))
WriteToLog ("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")

Set objFiles = Nothing
Set objTS = Nothing
Set objFolder = Nothing
Set objFSO = Nothing



End Sub


'==========================================================
' This is a simple subroutine to write a line to the log file
'==========================================================
Sub WriteToLog(xLine As String)

If xLine > "" Then

objTS.WriteLine (xLine)

End If

End Sub
 
Thanks Jim,
I will play with this and see if I can get it to work.

Charles
Walden's Machine, Inc.
Quality Assurance/Office Developer
 
Jim, I am having trouble with these lines:
Dim objFSO As FileSystemObject
Dim objFolder As Folder
Dim objFiles As Files
Dim objFile As File
Dim objTS As TextStream

It says - user defined type not defined. I put all your code in a module and am trying to call it from the print button on my form.

Any ideas why it gives that error on all of these lines?

Charles
Walden's Machine, Inc.
Quality Assurance/Office Developer
 
Never mind...found out why in the knowledge base.

Charles
Walden's Machine, Inc.
Quality Assurance/Office Developer
 
If this is standalone functionality you want go to google.com and do search for directory printer. There are quite a good selection of freeware progs to do what you want.[idea]


Sam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top