|
-
Jul 31st, 2000, 07:28 AM
#1
Thread Starter
Lively Member
Is there an easy way to get the root directory without using a directory list box and all of the other drive letters? I want it for the purpose of searching for a directory, where the user enters the name and program searches to find it.
Using VB6 Still Pluging away
-
Jul 31st, 2000, 07:59 AM
#2
New Member
You should create a file system object and a drive object and use the RootFolder property of the drive object. Lookup File System Objects in help and you'll be able to see all the stuff you can do with them. You'll also need to add "Visual Basic Scripting Runtime" or something like that to your references........
Email me if you have problems...
[email protected]
Good Luck.......
-
Aug 1st, 2000, 11:08 PM
#3
Fanatic Member
Clarify Please
Can i just get the question clear,
What you want is :
When the user enters a directory/folder name you want to see if it exists without having the file system controls?
If that is correct then see the helpfile under the keywords DIR and DIR$ it has samples too
Code:
The example uses Dir to determine all the subdirectories on drive C. To try this example, paste the code into the Declarations section of a form containing a list box named List1. Then press F5 and click the form.
Const ATTR_DIRECTORY = 16 ' Declare form constant.
Sub Form_Click ()
ListSubDirs "C:\" ' Call ListSubDirs
End Sub
Sub ListSubDirs (Path)
Dim Count, D(), I, DirName ' Declare variables.
DirName = Dir(Path, ATTR_DIRECTORY) ' Get first directory name.
'Iterate through PATH, caching all subdirectories in D()
Do While DirName <> ""
If DirName <> "." And DirName <> ".." Then
If GetAttr(Path + DirName) = ATTR_DIRECTORY Then
If (Count Mod 10) = 0 Then
ReDim Preserve D(Count + 10) ' Resize the array.
End If
Count = Count + 1 ' Increment counter.
D(Count) = DirName
End If
End If
DirName = Dir ' Get another directory name.
Loop
' Now recursively iterate through each cached subdirectory.
For I = 1 To Count - 1
List1.AddItem Path & D(I) ' Put name in list box.
ListSubDirs Path & D(I) & "\"
Next I
End Sub
DocZaf
{;->
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|