473,606 Members | 2,110 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DirectoryInfo.G etFiles()

Hi,

I want to get a list of files matching certain extensions, such as
"*.jpg;*.gi f" (i.e. all files ending with .jpg and .gif).

I was using DirectoryInfo.G etFiles(string) method. Unfortunately it appears
that I cannot have something like:
dirInfo.GetFile s("*.jpg;*.gif" ); // where dirInfo is of type
DirectoryInfo

Help.

Thanks.
Nov 15 '05 #1
4 4683
I couldn't find any method in the DirectoryInfo that
suffices your requirement. I've pasted a some stuff that
you may want to have a look at.

Its kinda brute....

/////////////////////////////////////////////////////////
DirectoryInfo directoryInfo = new DirectoryInfo ("c:\\");
FileInfo [] fileInfo = directoryInfo.G etFiles ();
ArrayList arrayList = new ArrayList ();
string [] filter = {".exe", ".bat", ".txt", ".log"};

foreach (FileInfo fi in fileInfo)
foreach (string s in filter)
if (s == fi.Extension) arrayList.Add (fi);

return (FileInfo[])arrayList.ToAr ray(typeof (FileInfo));
////////////////////////////////////////////////////////

-----Original Message-----
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.G etFiles(string) method. Unfortunately it appearsthat I cannot have something like:
dirInfo.GetFil es("*.jpg;*.gif "); // where dirInfo is of typeDirectoryInf o

Help.

Thanks.
.

Nov 15 '05 #2
Pluto <Pl***@Pluto.co m> wrote:
I want to get a list of files matching certain extensions, such as
"*.jpg;*.gi f" (i.e. all files ending with .jpg and .gif).

I was using DirectoryInfo.G etFiles(string) method. Unfortunately it appears
that I cannot have something like:
dirInfo.GetFile s("*.jpg;*.gif" ); // where dirInfo is of type
DirectoryInfo


Why not just ask for each of them separately and then combine the
results? It would be pretty easy to write a utility method to do
precisely that.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3
Thanks.
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Pluto <Pl***@Pluto.co m> wrote:
I want to get a list of files matching certain extensions, such as
"*.jpg;*.gi f" (i.e. all files ending with .jpg and .gif).

I was using DirectoryInfo.G etFiles(string) method. Unfortunately it appears that I cannot have something like:
dirInfo.GetFile s("*.jpg;*.gif" ); // where dirInfo is of type
DirectoryInfo


Why not just ask for each of them separately and then combine the
results? It would be pretty easy to write a utility method to do
precisely that.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #4
Thanks.
"Amit Khot" <am*******@hotm ail.com> wrote in message
news:25******** *************** ******@phx.gbl. ..
I couldn't find any method in the DirectoryInfo that
suffices your requirement. I've pasted a some stuff that
you may want to have a look at.

Its kinda brute....

/////////////////////////////////////////////////////////
DirectoryInfo directoryInfo = new DirectoryInfo ("c:\\");
FileInfo [] fileInfo = directoryInfo.G etFiles ();
ArrayList arrayList = new ArrayList ();
string [] filter = {".exe", ".bat", ".txt", ".log"};

foreach (FileInfo fi in fileInfo)
foreach (string s in filter)
if (s == fi.Extension) arrayList.Add (fi);

return (FileInfo[])arrayList.ToAr ray(typeof (FileInfo));
////////////////////////////////////////////////////////

-----Original Message-----
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.G etFiles(string) method.

Unfortunately it appears
that I cannot have something like:
dirInfo.GetFil es("*.jpg;*.gif "); // where dirInfo is

of type
DirectoryInf o

Help.

Thanks.
.

Nov 15 '05 #5

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

Similar topics

2
20206
by: Demetri | last post by:
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.
0
459
by: Glenn Venzke | last post by:
I have an aspx page that is set up to copy backed-up DB files from a shared directory to a local folder. For some reason, it is being denied access to the network share. I have the web app running under a domain account that I know for a fact has access. it works fine when I log on to the network and browse the directory manually. Even when I grant full control to everyone on the share and the underlying folder itself, I still can't access...
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 there anything I can do to do this. Here is my code that i am using; Dim dirInfo as New...
3
2377
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 about a gig of files in this directory (about 5000 files) and using getFiles is slower than anything I...
13
2605
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 DirectoryInfo.GetDirectories), it can take forever. Some of the directories have thousands of files in them. So, my...
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 GetFiles hits certain directories (for example, a System Volume Information directory). If this were...
0
8009
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7939
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
8432
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8428
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
6753
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5962
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
5456
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
3964
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1285
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.