Hello and welcome to our community! Is this your first visit?
Register
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
    Posts
    2
    Thanks
    0
    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
    Location
    UK
    Posts
    1,137
    Thanks
    0
    Thanked 0 Times in 0 Posts
    do you have any thoughts or code, as it may help others to help you.

    scroots
    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
    Posts
    2
    Thanks
    0
    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
    Posts
    1,059
    Thanks
    0
    Thanked 13 Times in 13 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:

    http://msdn.microsoft.com/library/de...l/vafctdir.asp

    Code:
    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
    HTH,

    -sage-
    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
    •