View Full Version : Visual Basic search for folder using wildcards

12-07-2004, 02:09 AM
I am currently using VB6 and need to search for a folder using a wildcard. The folder is 4 characters long and there might be more than one folder. Need help! Thanks.

12-07-2004, 07:16 PM
do you have any thoughts or code, as it may help others to help you.


12-09-2004, 01:56 AM
I don't have any code yet, but all I'm trying to do is let's say, if there is a 2004 folder or 2003 folder or 2002 folder, I need to pull up any folder which is a year folder. So then, I will have to do 200* to pull up those three folders. I'm not sure if VB6 has any way of doing this.

12-09-2004, 02:34 AM
Since VB does nothing more than use the FSO (File System Object) for a case like this, then as long as the FSO supports a mask then yes, it can be done. Not to mention the VB does support its own internal DIR command.

I am at work and don't have any code readily available but this should be of help:


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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum