473,750 Members | 2,500 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Jul 12 '06 #1
2 2259
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
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
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



Jul 13 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2015
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 directory as configure.py and unit_test.py. But only SOME of them. Anyone have any ideas? -- - rmgw
3
7005
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 for Python. I'd be using it in Linux to regularly search for files with a script. Is this a good application for Python or does Perl have more functionality for quick & simple scripting in Linux? Thanks.
1
3726
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
18067
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 properties. If anyone know how to improve my method, or know a better one, he's welcome :-) Thanks,
1
7595
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. Just about every source I can find on the 'net for processing subdirectories points you at Find::Find.  However, I'm trying to do something like this: enter directory open INDEX, ".\index.html" print INDEX HTMLheader
2
1712
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 as follows: private string FileShare(string strURL) { string files; DateTime datLastWriteTime; DateTime datNewLastWriteTime;
0
1687
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 have 2 problems: First, I can't find a control that will let the user browse the file system and specify a directory - the only one I can find is the one that lets the user specify a file.
4
1345
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
3081
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 want to replace all of them. You need to look at it in a case-by-case basis. What can you do? Answer: emacs.
0
8839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9398
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9257
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6811
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6081
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4894
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2809
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2227
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.