How to find files in a directory

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • graphicsxp

    How to find files in a directory

    Hi,

    How can I open all the files in a directory, which names match a
    particular string ?

    Say I have a string like 'a file name to find' and I want to find and
    open all the files of a given directory, which name contains that
    string.

    Here is how I open the file of a directory. How can it be modified to
    find open only the right files?

    Imports System.IO
    Sub Dir(Optional ByVal sDirectory As String = ".")
    Dim sFiles() As String
    Dim i As Integer
    sFiles = Directory.GetFi leSystemEntries (sDirectory)
    For i = 0 To sFiles.GetUpper Bound(0)
    Console.WriteLi ne(sFiles(i))
    Next
    End Sub

    Thanks

  • graphicsxp

    #2
    Re: How to find files in a directory

    I forgot to mention that I know about the pattern argument to
    GetFileSystemEn tries but it seems to work only if the pattern matches
    the exact name + extension of the file.
    I want to find files, which name contain the pattern, and I don't care
    about hte extension.

    Thanks

    graphicsxp wrote:
    Hi,
    >
    How can I open all the files in a directory, which names match a
    particular string ?
    >
    Say I have a string like 'a file name to find' and I want to find and
    open all the files of a given directory, which name contains that
    string.
    >
    Here is how I open the file of a directory. How can it be modified to
    find open only the right files?
    >
    Imports System.IO
    Sub Dir(Optional ByVal sDirectory As String = ".")
    Dim sFiles() As String
    Dim i As Integer
    sFiles = Directory.GetFi leSystemEntries (sDirectory)
    For i = 0 To sFiles.GetUpper Bound(0)
    Console.WriteLi ne(sFiles(i))
    Next
    End Sub
    >
    Thanks

    Comment

    • tomb

      #3
      Re: How to find files in a directory

      I wouldn't redefine the Dir() function - that's already defined in the
      VB runtime. If you use the default Dir() function, then you can use it
      to continually find the file pattern you are looking for.

      T

      graphicsxp wrote:
      >I forgot to mention that I know about the pattern argument to
      >GetFileSystemE ntries but it seems to work only if the pattern matches
      >the exact name + extension of the file.
      >I want to find files, which name contain the pattern, and I don't care
      >about hte extension.
      >
      >Thanks
      >
      >graphicsxp wrote:
      >
      >
      >>Hi,
      >>
      >>How can I open all the files in a directory, which names match a
      >>particular string ?
      >>
      >>Say I have a string like 'a file name to find' and I want to find and
      >>open all the files of a given directory, which name contains that
      >>string.
      >>
      >>Here is how I open the file of a directory. How can it be modified to
      >>find open only the right files?
      >>
      > Imports System.IO
      > Sub Dir(Optional ByVal sDirectory As String = ".")
      > Dim sFiles() As String
      > Dim i As Integer
      > sFiles = Directory.GetFi leSystemEntries (sDirectory)
      > For i = 0 To sFiles.GetUpper Bound(0)
      > Console.WriteLi ne(sFiles(i))
      > Next
      > End Sub
      >>
      >>Thanks
      >>
      >>
      >
      >
      >

      Comment

      Working...