Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  HOME    TRACKER    Visual Basic

Directory Tree

How do I make a directory list box using a tree view, like in explorer? I want my program to have more of a professional look, I need my user to chose a directory to work in, but I don't want to use the run-of-the-mill boring one that MSVB6 gives you.

Any ideas? Cheers,


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Directory Tree

In many apps i have seen a dialog box which lets you select a folder...which is displayed in a tree style...(like in explorer) with OK and Cancel button.

How to make that ?


Need Help!--directory Tree In Vb6?
I have no idea how to begin with writing code to populate a tree view control in visual basic , the tough part is it should be recursively looping through a given directory on hard drive and display the folder tree.

any sample code will be welcome.


Directory File Tree
how would you make a directory tree of your entire computer and save it as a single file? ca that be done? i've been looking around for an idea but i'm stumped..

Copy A Directory Tree
I think I've done this in the past but I just can't find any records in my computer.
I have 2 directories, srcDir and dstDir. I want to loop over all files, folders and subfolders of srcDir and copy them to dstDir maintaining the original structure of any subfolders + sub-subfolders, etc in srcDir.

Do I have to use the FSO or what?

How Can I Copy A Whole Directory Tree
Hello. How can I copy a whole directory tree? Thanks.

Directory Tree View
I'm trying to create a Directory Tree View with the TreeView control, I have successfully created the Directory Structure in the treeview but i don't know how to make it so that if you select the top node, that all the children are checked as well. Does anyone know how to do this or a control that can.


Creating A Non-Existing Directory Tree
Alright... I've got this Function that works, but it's certainly not very elegant and I'm not even entirely sure why it works... But it does, and digging through the forum archives I didn't really find a good solution. So here's what I've got.

Public Sub MakeDir(Path As String)
On Error Resume Next
Dim LoopCount As Integer: LoopCount = 0
Dim oldpos As Integer: oldpos = 1
Dim pos As Integer: pos = 0
Dim StartPos As Integer: StartPos = 1

Do While oldpos <> 0
pos = InStr(oldpos, Path, "", vbTextCompare)
LoopCount = LoopCount + 1
'MsgBox ("Left to Pos: " + Left(Path, pos) + vbCrLf + _
"Loop Count: " + CStr(LoopCount) + vbCrLf + _
"Pos/OldPos: " + CStr(pos) + "/" + CStr(oldpos))

If InStr(StartPos, Mid(Path, StartPos, pos), ":") <> 0 Then
StartPos = InStr(StartPos, Left(Path, pos), ":") + 1
pos = InStr(StartPos, Path, "", vbTextCompare)
Else: ChDir (Mid(Path, StartPos, pos))
End If

oldpos = pos + 1
If InStr(StartPos, Mid(Path, StartPos, pos), ".") Then Exit Do
If Err.Number = 76 Then
MkDir (Left(Path, pos))
ElseIf Err.Number = 75 Then Exit Do
End If
End Sub

Any thoughts on the subject would be appreciated... This assumes you are passing the full path to a local drive but I know I'm going to run into all kinds of problems when I go to work tomorrow and the app.path is across a network drive and comes up \oldblue*Path*, as well as the first time I encounter a directory with a . in it. Also if anyone knows how to search from right to left through a string it would help as well.

Thanks in advance.

Directory Tree In Access Vb **Resolved**
I am importing a series of files that are all located in the same folder. I need to setup a program that will all the users to change the location of the folder where the files are located. I have tried using the Windows Common Dialogs, but you have to select a file to use that. Is there any way to select a folder programmatically in Access 2000?

Need Help Creating A Backup Directory Tree
I want to write a routine to backup my laptop into an external drive.

One of my directory has subdirectories within subdirectories. Some is one one deep but some are 2, 3 or 4 deep.

I am having trouble creating a routine that would drill down to every subdirectory automatically and back up the files in there.

Can someone help please?

Scan For Files In Directory Tree
I need to automate deleting files from a directory tree that are over 150 days old.  I found the code below which I'm using as a proof of concept.  It processes the files in the root but I can't figure out how to go below the root directory.
CODE    Dim objFSO As New FileSystemObject
    Dim objFile As File
    Dim objFolder As Folder
    Set objFolder = objFSO.GetFolder("Root Directory Path")
    For Each objFile In objFolder.Files
        List1.AddItem objFile.Name & ", " & objFile.DateCreated
        If DateDiff("d", objFile.DateCreated, Date) > 150 Then
            List2.AddItem objFile.Name & ", " & objFile.DateCreated
        End If
    Next objFile
    Set objFSO = Nothing
    Set objFile = Nothing
    Set objFolder = Nothing

Copy Directory Tree Recursion. Broken
I am writing a small GUI less program that copys a directory tree (just the folders not the files) and the resursive function I used to do it dosn't work and I have no idea Why. heres the code

Sub CopyDirTree(ByVal StartDir As String, CopyHere As String)
'Declare Variables
Dim X As String
Dim Y As String
Dim s As String
Dim currdir As String
Dim dirlist As New Collection

If Right$(StartDir, 1) <> "" Then StartDir = StartDir & ""
dirlist.Add StartDir
While dirlist.Count
'remove current directory from directory list
currdir = dirlist.Item(1)
dirlist.Remove 1
'find all files and subdirectories in current, add to list
s = Dir$(currdir, vbDirectory)
MsgBox s
While Len(s)
If (s <> ".") And (s <> "..") Then 'get rid of "." and ".."
's is empty here.
If GetAttr(currdir & s) = vbDirectory Then 'add the subdirectory
dirlist.Add currdir & s & ""
'Set the path to the folders that need to be copied
X = Right$(StartDir, Len(StartDir) - 3)
X = Right$(X, Len(X) - InStr(X, ""))
Y = CopyHere & X
MkDir Y
'a file was found (do nothing)
End If
End If
s = Dir$
End Sub
All I know is the variable s is empty at the indicated spot. I ran this function on D:windows so there is definatly files and folders there.

.hlp Contents Tree Only Works In Original Directory...

My .hlp file contents functions normally in the directory it was made in but nowhere else. Even on the same computer, if i copy the .hlp to another location it doesn't open with a contents tree like in the orig dir.

As far as i can tell all relative paths are correct.....

I've tried:
Opening it with WinHlp32 manually: opens but w/o contents tree except for orig dir.

I read ( that WinHlp automatically builds the contents .GID file so i didn't copy that to new dir. It did make a .GID file.

I did copy the .fts file though since MS recommended it for cd distributions.

Also tried installing it with setup but doesn't open with contents tree either.

In code, i've tried:

strHlp = App.Path & "FASDHELP.HLP"

' first tried:
OpenFile Me.hwnd, strHlp
' which uses ShellExecute Lib "shell32.dll"
' help opens with no contents tree

' then after reading some threads tried:
WinHelp Me.hwnd, strHlp, HELP_CONTENTS, ByVal 0
' which uses WinHelp Lib "user32.dll"
' help opens with no contents tree

' and then:
Shell (GetWinDir() & "WinHelp.exe " & strHlp), vbNormalFocus
' which gave me the error that it's not a windows help file; a new version of help is needed.
I'm pretty much out of ideas... anyone?... vb help meister!!


Directory Tree View, Window Drag
Hello Folks

Does anyone know how I can make a Directory Tree view like the one used in WinAmp when you click on Play > Directory. Also, I would like to make my VB 6.0 Forms have the little triangle on the button right like Microsoft program in Win2K/ME/XP that lets you expand the window size when the window is restored.

Like always, thank you in advance.

Show File Directory Tree Question
Try having a look at this, and see it might help you.

User Tree In Novell Directory Services (NDS)

Kindly help with the following: Can some pls help with VB code that find/get NDS tree where the userid belongs.

Thank you

Need To Recreate The Directory Tree From Windows Explorer...
In several applications, we need to be able to provide the ability to browse through the network as well as the local machines. In the past, we have relied on the Windows Common Control or implementing the SHBrowseForFolder from Shell32 to have access to Network Neighborhood as well as the local machine.

However, new requirements require this to be similar to Windows Explorer...where we are selecting the directory and filename seperate and in conjunction with other selections and controls.

Does anyone know of a control that will reproduce the left pane of Windows Explorer (the directory tree with appropriate icons) or the directory pulldown box used in the Common Control?

Thank you in advance for any suggestions...

How To Collaps A Tree Node With Children And Have It Clear The Children (Tree.Nodes.Remove

I have a tree that has topics, so for example in the following:

Aouto type
            Sports car
        Motor cycle

I notice that If I colllaps a level it still is retaining the children structor in memory, where the first time through it builds them.
I need that if I collapse the car node it to totaly clears its children and rebuild them again on expansion. Is there a tree function or something that would do this? I think the answer is in using Tree.Nodes.Remove some how, but I am not sure how I would use it here.

Thank you

Edited by - itmasterw on 6/23/2006 8:12:29 AM

Count Files In A Directory, AND Sub Directory, - Copy A Directory...

how do u:

1) count how many files are in a directory, and its sub directory?

2) How do you copy a directory, AND count how many files out the directory has been copied?


Just Move A Directory, Into An Exsisting Directory, Replacing All Files That Exsist .
Just Move a directory, into an exsisting directory, replacing all files that exsist , if i am moving the directory to, and the file already exsists there,

Just like in Windows Explorer,

How do i do this?

(urgent, Need Help) Moving File From One Directory To Another Directory Problem
i have a question regarding about the problem that stated at the title.

i need to make sure that after the flat file's data dumped into database then only the particular flat file can be move from one directory to another directory.

i failed to do it, please help

please refer to the attached below

Copy All Files In Current Directory To Temp Directory
ok heres the situation, i need to copy all the files in the app.path directory to another directory....the problem is, with the current code, i can run the app from a folder on the hdd fine, but i get an error when trying to run the app from the root directory of the cdrom....heres my code...btw apppath is a function which returns "D:" when running from the cdrom

error is invalid procedure argument or call, on the copy function

VB Code:
Private Declare Function GetTempPath Lib "kernel32" Alias "GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long'--------    Dim fso As New FileSystemObject    Dim Folder2Copy As Folder    Set Folder2Copy = fso.GetFolder(AppPath)    If Not fso.FolderExists(TempPath & "InternetSignup") Then fso.CreateFolder TempPath & "InternetSignup"        Folder2Copy.Copy TempPath & "InternetSignup", True'--------Private Function TempPath() As String    'Function to control the TempPath API    Dim strBuffer As String    Dim lngLen As Long    lngLen = 1024    strBuffer = Space(lngLen)        If (GetTempPath(lngLen, strBuffer) > 0) Then        strBuffer = Left(strBuffer, InStr(1, strBuffer, vbNullChar) - 1)    Else        strBuffer = ""    End If        TempPath = strBuffer    End Function

EDIT: Resolved by moving all files to a subfolder on the cdrom

Directory Dialog That Returns A Directory Location Navigated To
Is there an existing control that I can use that will allow me to navigate to a directory with methods to return that directory. The ones coming with VB6 forces one to input a name and then returns the directory path and the file name which then has to be parsed off.

How To Retrieve The Current Directory And Create A Directory In It Using VB Code
I am using common dialog control to get the file name, user wants to save. Also I have a text box in which the user can enter the filename manually. Incase the user enters the filename to be saved manually, how can I validate the filename and Directory using VB. Secondly if the directory path specified by the user doesnot exist , how can i create the directory structure through VB code. Finally how can I retrieve the curr Directory path, incase user only enter the filename.
I would greatly appreciate any help in this regard. Thanks


Treeview Directory Listing With Add Directory Option
Hi there !
What i want is a treeview directory listing with an Add Directory Option which will add a directory and put it in the right place.

the code i have is this but it does not have a create directory option

Thanks !!!

Public Function vbGetBrowseDirectory(ByVal hwnd) As String


Dim r As Long
Dim pidl As Long
Dim tmpPath As String
Dim pos As Integer

bi.hOwner = hwnd
bi.pidlRoot = 0&
bi.lpszTitle = "Select the directory"

'get the folder
pidl = SHBrowseForFolder(bi)

tmpPath = Space$(512)
r = SHGetPathFromIDList(ByVal pidl, ByVal tmpPath)

If r Then
pos = InStr(tmpPath, Chr$(0))
tmpPath = Left(tmpPath, pos - 1)
vbGetBrowseDirectory = ValidateDir(tmpPath)
Else: vbGetBrowseDirectory = ""
End If

End Function

Public Function ValidateDir(tmpPath As String) As String

If Right$(tmpPath, 1) = "" Then
ValidateDir = tmpPath
Else: ValidateDir = tmpPath & ""
End If

End Function

Make A Directory Hidden? Killing A Directory?
How do I make a directory hidden? How do I kill an entire hidden directory?

Upload All Files In Directory To Remote Directory
Hi, I want to upload all files in a specified directory to a remote directory on a FTP server, how could I go about doing that? I was thinking maybe a FileListBox could come into play, but I am probably wrong.


Create Directory If Directory Does Not Exist
I need to make sure these 3 directories exist, if not create them:


Does anyone have code that would do this? Thanks!!!

Browse For Directory With Add Directory Buttons.
Alright I'm using the standard api (can be found here at for showing the browse for folder windows. It is great.

But now I want to use it in my install app.
Nou can I get the add folder button in it???

Thanks in advance,

Deleting All Files From A Directory But Not The Directory Itself?
Dim oFSO As Object
Set oFSO = CreateObject("Scripting.FileSystemObject")
oFSO.DeleteFolder "I:Documents and SettingsVaxoPLocal SettingsTemporary Internet Files", True

How can I delete all files and folders in a folder, but not delete the folder itself? (IE delete all files and folders in the temporary internet files folder, but not the temporary folder itself)

All other methods ive tried (nukill, the api, kill) dont work.. this is the only one that has so far.. how can i delete all files except the directory itself?

Reading All Files In A Directory And Sub Directory
Hello folks,

How would I do this? I want a program when I choose a folder, it will they give me a list of all files in that folder and all sub folders?

Getting Full Directory And Drive Paths With The Drive/directory/file Controls
when i have a text editing program i wish the user to allow the user to find the file with other means than a common dialog box, i want to use drive/folder/file controls, but i dunno how to get the full path of the file... any suggestions?

Winsock And Directory List Box To Get Directory List Of A Remote System
I am using winsock control to transfer the items listed in a directory listbox, to display the list of folder names.The problem is if we move to c:dir1dir2dir3 then again come to c: i am still getting the directory list of c:dir1dir2dir3 .All the changes are done in the directory list box by coding.

Tree Help
i have made a tree with checkboxes, i want to write a code that on its click event the node itself get selected/deselected and if it is a parent node then all of its child should also get selected/deselected. the tree has only two levels. this is the initial code which i write

VB Code:
Dim nd As Node    Set nd = Tree.Nodes.Add()    nd.Key = "AB"    nd.Text = "Address Book"    nd.Tag = "HEADS"                Set nd = Tree.Nodes.Add()    nd.Key = "QR"    nd.Text = "Query List"    nd.Tag = "HEADS"

Could anyone tell me the basics of using a treeview. Any help would be apprecaited

VB Tree
Can anyone tell me how to make pre order traversal in a tree view control.
I tried with x.firstsibling.index to x.lastsibling.index but problem is it often visits same node more than once because of index.

AVL Tree In VB6 ??
Anyone have a sample of code for an AVL tree structure in VB? It would be a simple tree of numbers or strings.


How do i code a click event for an item in a tree? for example i want to open a report when report1 is clicked in the tree.

Is there an actual click event for a tree.


Another Branch On The Tree!
Dear All,

I am attempting to dynamically populate a TreeView object with data from a database, but keep receiving the Invalid Object error when I try to add a child to a parent. The code so far is...

'Now add all of the root level codes to the tree...
While Not .EOF

'First add the parent node...
tvwCodeList.Nodes.Add , , _
.Fields("CODE"), Left(.Fields("CODE"), 1) & ": " & _
IIf(.Fields("CCSCD_SUBTYPE") = "MPROB", _
" (" & .Fields("OPCS") & ")", _
" (" & .Fields("ICD10") & ")"), _
IIf(.Fields("CCSCD_SUBTYPE") = "MPROB", "picThermom", "picSurgeon")

'Now add a single child node...
tvwCodeList.Nodes.Add .Fields("CODE"), tvwChild, _
"LOAD" & .Fields("CODE"), "Loading...", , "picDisc"

'Move to the next record...
Basically, there are approx 70000 codes I need to display in the TreeView, and to keep speed and memory to a maximum, I have decided to take the approach of when a node expands, other expanded nodes are collapsed, data removed from the underlying nodes, and the selected node to be expanded is then populated.

The error lies in the creation of the temporary "Loading..." node (the second node added in the loop), and I just can't spot what's wrong.

The creation of the first node is fine. Initially, I created only the root nodes, and they worked okay. I thought it might have something to do with the dots on the end of the code (a typical code takes the form, 7........., then it's children will be 70........, 71........, and their children 701....... and so on).

So, if anyone can help, I'd really appreciate it.

Many thanks in advance,

How Tell When No Itemselected In Tree ?

I have a tree view whose root level can be changed by an adjacent dirlistbox. I also have a GO button that will respond to what is selected in the treeview (folder / file). But what I can't figure out is how to tell if there is nothing selected in the tree. This happens when i) the program first starts out, and ii) after I have used the dirlistbox to change the root.

What I was hoping to do, is if nothing is selected, then use the selection in the dirlistbox or the root of the current tree (i havent decided yet)

Thanks for any help.


Tree In Combo Box
What control can I use t display a tree structure in a combo box.. like the one on the open dialog? with the images and all?

Event Tree
Is there such a document that will explain the order/precedence of events for Access objects? I have tried looking in the help file but can't seem to find it.


Tree View
Hi All,

i am using the windows common control 6's treeview.

there is this option which is the check box.
does anyone know how to make the child node to be uncheck/check automatically when the parent is uncheck/check

please advise. Thanks alot.

Tree View
how can i place the node names like a tree. i'm new to handling the tree view, please give me a tutorial. thanks in advance..................

Tree View
Hi i want a treeview to show all files and folders in a specified directory so it ends up looking like this.

Main Directory
--- Folder 1
------ File 1
--- Folder 2
------ File 1
------ File 2
------ File 3
--- Folder 3
------ File 1

How would i do this.

Tree View
I created a table with 10 different job profiles and with each required skill. Id' like to use a treeview to display them, and i don't have a clue on how to elaborate it.


profile 1; skill 1
profile 1; skill 2
profile 1; skill 3
profile 1; skill 4
profile 2; skill 1
profile 1; skill 2

Ideas ,please?!

Tree View

I have a TreeView which I am using a piece of code posted on this forum by Garrett Sever that changes the background colour of the treeview.

This works, but the one problem I'm having is when a user selects a node the selected item's background colour can clash with it's foreground colour. I belive it gets it colours from the desktop colours. Is there anyway I can override this and use my own colours for the selection ?


Delete Tree
Can I delete a folder, all its subfolders and files, all their subfolders and files, etc. Without having to loop through each folder deleting files individually?

How To Use Tree View
can someone show me how to used the tree view in visual basic please!?

System Tree
Is it posible to add some folders into windows's system tree.
I mean:

--My Computer
--My documents
--Internet Explorer
--Net Hood
--My added folder or file

Is there any API function or I need to investigate my system registry manualy?

Copyright 2005-08, All rights reserved