473,585 Members | 2,552 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DirectoryInfo.G etFiles 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 20205
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.L astIndexOf 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.co m> 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.co m> 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
9995
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 javascript code). I'm never opening the files or accessing them in any other way. Problem is, that once this ASP.NET page is accessed, we can then no...
4
4683
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. Unfortunately it appears that I cannot have something like: dirInfo.GetFiles("*.jpg;*.gif"); // where dirInfo is of type DirectoryInfo
8
1894
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 directory info that would contain the file name without the extension. Can I add an attribute or an entry to accomplish this? If so, how, if not, is...
3
2376
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 ; ccc++ ) { System.Web.HttpResponse.Response.Write( "<a href=\"" + Request.MapPath(".") + "/" + HttpUtility.HtmlEncode(ppp.Name) + "\">link</a>" );
5
6492
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 DirectoryInfo.GetFiles wondering if anyone had the same issues I built my function to get the files, using a searchPattern filter (*.tif) in which case I have...
13
2601
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 of directories and files. I've figured out DirectoryInfo (it's pretty simple), but when I invoke DirectoryInfo.GetFiles (or even...
2
4607
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 = objDi.GetFiles();
1
2547
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 dt.Columns.Add("FileName", GetType(String)) dt.Columns.Add("CeateTime", GetType(String)) dt.Columns.Add("Length", GetType(String))
2
11628
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 the DirectoryInfo.GetFiles returns nothing. When I put a break in and check it out further, it looks like I'm getting ERROR_ACCESS_DENIED when the...
0
7908
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8336
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...
1
7950
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8212
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...
0
6606
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
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...
0
3835
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1175
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...

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.