473,396 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 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 2229
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Richard Wesley | last post by:
I am using coverage.py to run my unit test suite to check for missing tests. It mostly works, but for some mysterious reason, some of the files can't be found because they are not in the same...
3
by: Greg Yasko | last post by:
Hi. Does anyone know if there's an equivalent of Perl's file::find module in Python? It traverses a directory. I've googled extensively and checked this newsgroup and can't find anything like it...
1
by: Xah Lee | last post by:
suppose you want to do find & replace of string of all files in a directory. here's the code: ©# -*- coding: utf-8 -*- ©# Python © ©import os,sys © ©mydir= '/Users/t/web'
1
by: Thieum22 | last post by:
Hi, I try to go through a directory and it's subdirectories to reah the properties of each files. But I have a problem to set active the directory where the files are, in order to display their...
1
by: Dan Jones | last post by:
I'm writing a script to process a directory tree of images.  In each directory, I need to process each image and generate an HTML file listing all of the images and links to the subdirectories....
2
by: Rosa | last post by:
Hi, I'm looking for an elegant solution on how to find the youngest file within a given directory. At the moment I'm storing all files in an array and loop through it comparing the creation date...
0
by: haylow | last post by:
Hi I am new to ASP.NET and am working on an application that runs on a webserver. The user will open up the web interface in a browser on their local machine and enter a path to a directory. I...
4
by: Milsnips | last post by:
Can anyone help out on this one? i would like to find out all the ASPX and ASCX pages that are in my project, and return them in an arraylist. thanks, Paul.
0
by: Xah Lee | last post by:
Interactive Find and Replace String Patterns on Multiple Files Xah Lee, 2006-06 Suppose you need to do find and replace of a string pattern, for all files in a directory. However, you do not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.