USING VB6
I want to search a file from the path.
For Example.
Path = "C:\Newfolder\" file name = *.txt, *.fin
I want to get all the *.txt, *.fin file from the newfloder.
Need VB6 code Help.
USING VB6
I want to search a file from the path.
For Example.
Path = "C:\Newfolder\" file name = *.txt, *.fin
I want to get all the *.txt, *.fin file from the newfloder.
Need VB6 code Help.
Use the Scripting.FileSystemObject.
Call it with GetFolder("C:\Newfolder"), then loop through the files in that folder with the .Files property and filter them on extensions using the GetExtensionName method.
For example:
Dim fso as Object: Set fso = CreateObject("Scripting.FileSystemObject")
Dim f as Object
For Each f in fso.GetFolder("<folderpath>").Files
If fso.GetExtensionName(f.Path) = "txt" Then 'or maybe it's .txt, I'm not sure
' also test for 'fin'
'... do stuff
End If
Next f
Check out the Scripting.FileSystemObject.
In your project add a reference to the "Microsoft Scripting Runtime".
Then you can do something like this:
Dim fso As Scripting.FileSystemObject
Set fso = New Scripting.FileSystemObject
Dim fld As Scripting.Folder
Set fld = fso.GetFolder("d:\temp\newfolder")
Dim i As Integer
Dim ext As String
Dim fl As Scripting.File
For Each fl In fld.files
'get extension
ext = Mid(fl.Name, Len(fl.Name) - 2)
If ext = "txt" Or ext = "fin" Then
'do something with the file
End If
Next fl
This is one of the areas that got so much better with .NET.
Just drop-in a CDirDrill class that does it all for you, in full native VB6. Another excellent solution from Karl Peterson :)
The FileSystemObject is not recommended for a couple of reasons: one, it adds a dependency, and two, it depends on scripting, which may be disabled per policy. I've had bugs because some customer has managed to muck up scrrun.dll on their PC. Eliminate dependencies unless they're really helping you a lot.
BTW this question is a duplicate of this