|
-
Jul 15th, 2000, 05:26 AM
#1
Thread Starter
New Member
Hi,
Can anyone tell me how to obtain a list of files and folders within any folder in VB5, in order that I can process the files found. I'm not sure what control to use for this.
Your help would be greatly appreciated.
Many Thanks
Sean
-
Jul 15th, 2000, 06:48 AM
#2
Addicted Member
GET your VB5 HELP ready...
Now..quick.. go and refer the VB5 help file for
information about this function..
Dir
Code:
This example uses the Dir function to check if certain files and directories exist.
Dim MyFile, MyPath, MyName
' Returns "WIN.INI" if it exists.
MyFile = Dir("C:\WINDOWS\WIN.INI")
' Returns filename with specified extension. If more than one *.ini
' file exists, the first file found is returned.
MyFile = Dir("C:\WINDOWS\*.INI")
' Call Dir again without arguments to return the next *.INI file in the
' same directory.
MyFile = Dir
' Return first *.TXT file with a set hidden attribute.
MyFile = Dir("*.TXT", vbHidden)
' Display the names in C:\ that represent directories.
MyPath = "c:\" ' Set the path.
MyName = Dir(MyPath, vbDirectory) ' Retrieve the first entry.
Do While MyName <> "" ' Start the loop.
' Ignore the current directory and the encompassing directory.
If MyName <> "." And MyName <> ".." Then
' Use bitwise comparison to make sure MyName is a directory.
If (GetAttr(MyPath & MyName) And vbDirectory) = vbDirectory Then
Debug.Print MyName ' Display entry only if it
End If ' it represents a directory.
End If
MyName = Dir ' Get next entry.
Loop
If you can't pronounce my name, call me GURU 
-
Jul 15th, 2000, 09:23 AM
#3
This will list all files in a specific directory.
Code:
Dim FileFinder
FileFinder = Dir("C:\")
Do Until FileFinder = ""
List1.AddItem LCase(FileFinder)
FileFinder = Dir
Loop
If you'd like to list files with a certain extension:
Code:
Dim FileFinder
FileFinder = Dir("C:\*.exe")
Do Until FileFinder = ""
List1.AddItem LCase(FileFinder)
FileFinder = Dir
Loop
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
|