472,121 Members | 1,591 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,121 software developers and data experts.

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.GetFileSystemEntries(sDirectory)
For i = 0 To sFiles.GetUpperBound(0)
Console.WriteLine(sFiles(i))
Next
End Sub

Thanks

Jul 12 '06 #1
2 2124
I forgot to mention that I know about the pattern argument to
GetFileSystemEntries 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.GetFileSystemEntries(sDirectory)
For i = 0 To sFiles.GetUpperBound(0)
Console.WriteLine(sFiles(i))
Next
End Sub

Thanks
Jul 12 '06 #2
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
GetFileSystemEntries 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.GetFileSystemEntries(sDirectory)
For i = 0 To sFiles.GetUpperBound(0)
Console.WriteLine(sFiles(i))
Next
End Sub

Thanks



Jul 13 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Richard Wesley | last post: by
3 posts views Thread by Greg Yasko | last post: by
1 post views Thread by Dan Jones | last post: by
4 posts views Thread by Milsnips | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.