473,325 Members | 2,774 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,325 software developers and data experts.

DirectoryInfo.GetFiles Method

Using the GetFiles method of the DirectoryInfo instance
one can pass in a search pattern of string type.

For example:
DirectoryInfo di = new DirectoryInfo("C:\temp");
FileInfo[] fi = di.GetFiles("*.doc");

That code would return all the files with the doc
extension in the C:\temp folder. No problem.

However, suppose I want all the files that have the
word "Corporate" and "Audit" and "finance" in the files
name (not the files contents)?

This means if there are two files:
1. System finance.doc
2. Audit Finance Corporate.doc

The above should return just file number 2 since it
satisfies the requirement to have those three words in the
files name.

Any ideas on how to implement this?

Nov 15 '05 #1
2 20184
Hi,

AFAIK there is not a framework method for this, GetFiles expect a string
not a regex, solution:
Return all the files using GetFiles() and then filter them by yourself
using a regex or using FileInfo.Name.LastIndexOf method, this is not a good
solution , though . so I will go for the regex.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Demetri" <Re****@Spam.com> wrote in message
news:05****************************@phx.gbl...
Using the GetFiles method of the DirectoryInfo instance
one can pass in a search pattern of string type.

For example:
DirectoryInfo di = new DirectoryInfo("C:\temp");
FileInfo[] fi = di.GetFiles("*.doc");

That code would return all the files with the doc
extension in the C:\temp folder. No problem.

However, suppose I want all the files that have the
word "Corporate" and "Audit" and "finance" in the files
name (not the files contents)?

This means if there are two files:
1. System finance.doc
2. Audit Finance Corporate.doc

The above should return just file number 2 since it
satisfies the requirement to have those three words in the
files name.

Any ideas on how to implement this?

Nov 15 '05 #2
The Xceed FileSystem that comes with Xceed Zip for .NET enables you to do
stuff like this (and much more!):

DiskFolder folder = new DiskFolder( "c:\\temp" );
DiskFile[] files = folder.GetFiles( true, new AndFilter( "*corporate*",
"*audit*", "*finance*" ) );

Already implemented filters are: NameFilter (or passing a string),
AttributeFilter (or passing a FileAttribute), DateFilter, SizeFilter,
AndFilter, OrFilter, NotFilter. You can also derive from the base Filter
class and implement your own!

http://www.xceedsoft.com/products/ZipNet/
Martin Plante
Xceed Software Inc.
http://www.xceedsoft.com

"Demetri" <Re****@Spam.com> wrote in message
news:05****************************@phx.gbl...
Using the GetFiles method of the DirectoryInfo instance
one can pass in a search pattern of string type.

For example:
DirectoryInfo di = new DirectoryInfo("C:\temp");
FileInfo[] fi = di.GetFiles("*.doc");

That code would return all the files with the doc
extension in the C:\temp folder. No problem.

However, suppose I want all the files that have the
word "Corporate" and "Audit" and "finance" in the files
name (not the files contents)?

This means if there are two files:
1. System finance.doc
2. Audit Finance Corporate.doc

The above should return just file number 2 since it
satisfies the requirement to have those three words in the
files name.

Any ideas on how to implement this?

Nov 15 '05 #3

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

Similar topics

2
by: David Turner | last post by:
I have created an ASP.NET page that uses the System.IO.DirectoryInfo.GetFiles() method to get a list of files in a specific directory on our web server. (I simply use this list to build some...
4
by: Pluto | last post by:
Hi, I want to get a list of files matching certain extensions, such as "*.jpg;*.gif" (i.e. all files ending with .jpg and .gif). I was using DirectoryInfo.GetFiles(string) method....
8
by: Lyners | last post by:
I have code that retrieves all of the file names within a directory. After retriving them, I display the information in a datagrid. What I would like to do is add an extra output column on the...
3
by: xenophon | last post by:
This following innocuous code: System.IO.DirectoryInfo fff = new System.IO.DirectoryInfo(); System.IO.FileInfo ppp = fff.GetFiles( Request.MapPath(".") ); for( int ccc=0 ; ccc < ppp.Length ;...
5
by: CJ Taylor | last post by:
Hey Everyone, Sorry haven't been around to answer questions as much as usual (or at all for that matter) just been engrossed in a project. Anyways, dealing with an issue using...
13
by: Tom Scales | last post by:
OK, I admit, I am not a VB.NET expert and am still learning, but have run into an annoying problem. I'm writing a program that has to search the file system and therefore processes large numbers...
2
by: pittster | last post by:
Hi, I've bound a Gridview control to the GetFiles method Here is a code snippet: DirectoryInfo objDi = new DirectoryInfo(Server.MapPath("./somepath")); FileInfo arrFileInfo =...
1
by: jobs | last post by:
Say I only have a single file I want to get information on. How can I adapt this code? Dim dr As DataRow Dim fi As FileInfo Dim dir As New DirectoryInfo(filename) Dim dt As New DataTable...
2
by: RodneyAnonymous | last post by:
Hello everyone. I'm working on a simple utility that lists all files in a given directory with a given extension and outputs the results to a text file. I'm encountering issues while testing where...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.