Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Dec 2004
    Thanked 0 Times in 0 Posts

    Visual Basic search for folder using wildcards

    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.

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Thanked 0 Times in 0 Posts
    do you have any thoughts or code, as it may help others to help you.

    Spammers next time you spam me consider the implications:
    (1) that you will be persuaded by me(in a legitimate mannor)
    (2)It is worthless to you, when i have finished

  • #3
    New to the CF scene
    Join Date
    Dec 2004
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Super Moderator sage45's Avatar
    Join Date
    May 2002
    Thanked 15 Times in 15 Posts
    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.

    HTML & CSS Forum Moderator

    "If you don't know what you think you know, then what do you know."
    R.I.P. Derrick Thomas #58
    1/1/1967 - 2/8/2000


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts