Results 1 to 8 of 8

Thread: How to find multiple files with the same part of filename?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2006
    Posts
    28

    Arrow How to find multiple files with the same part of filename?

    Hi everyone,

    i was just wondering how to find multiple files with the same part of filename and just 1 character different.

    eg. if i want "abc_$.txt"

    i want to find "abc_1.txt", "abc_2.txt", "abc_3.txt", etc within the same directory

    thanks buds

  2. #2
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: How to find multiple files with the same part of filename?

    Something like this:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     Dim sFile As String
    5.     Dim sDir As String
    6.    
    7.     sDir = "C:\"
    8.     sFile = Dir(sDir & "abc_?.txt", vbArchive)
    9.    
    10.     Do Until Len(sFile) = 0
    11.         If sFile <> "." And sFile <> ".." Then
    12.             Debug.Print sDir & sFile
    13.         End If
    14.        
    15.         sFile = Dir
    16.     Loop
    17. End Sub

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2006
    Posts
    28

    Re: How to find multiple files with the same part of filename?

    coooool, it works, thanksssssss

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Oct 2006
    Posts
    28

    Re: How to find multiple files with the same part of filename?

    one more question,

    what if i want to get all file from a specific directory.

    eg. if i want "*.txt"

    i want to find all .txt files within the same directory

    thanks buds

  5. #5
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: How to find multiple files with the same part of filename?

    just change the search string - i'm also pretty sure that . and .. don't get returned if you specify a search string, so you can do:
    VB Code:
    1. Private Sub Form_Load()
    2.     Dim sFile As String
    3.     Dim sDir As String
    4.    
    5.     sDir = "C:\"
    6.     sFile = Dir(sDir & "*.txt", vbArchive)
    7.    
    8.     Do While Len(sFile)
    9.         Debug.Print sDir & sFile
    10.        
    11.         sFile = Dir
    12.     Loop
    13. End Sub

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Oct 2006
    Posts
    28

    Re: How to find multiple files with the same part of filename?

    Thanks, but sFile giving me a empty string?!? (see code below)

    Private Sub Form_Load()
    Dim sFile As String
    Dim sDir As String

    sDir = "C:\"
    sFile = Dir(sDir & "*.txt", vbArchive) <-- sFile giving me a empty string?!?

    Do While Len(sFile)
    Debug.Print sDir & sFile

    sFile = Dir
    Loop
    End Sub

  7. #7
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: How to find multiple files with the same part of filename?

    you've definitely got some txt files in C:\ ?

    try
    VB Code:
    1. sFile = Dir(sDir & "*.txt")

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Oct 2006
    Posts
    28

    Re: How to find multiple files with the same part of filename?

    haha, ops, i didn't have any txt file in C:.. it works now, thankss bud

Posting Permissions

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



Click Here to Expand Forum to Full Width