473,509 Members | 3,095 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DirectoryInfo.GetFiles()

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

Help.

Thanks.
Nov 15 '05 #1
4 4676
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.GetFiles ();
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.ToArray(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.GetFiles(string) method. Unfortunately it appearsthat I cannot have something like:
dirInfo.GetFiles("*.jpg;*.gif"); // where dirInfo is of typeDirectoryInfo

Help.

Thanks.
.

Nov 15 '05 #2
Pluto <Pl***@Pluto.com> wrote:
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


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.com>
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.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Pluto <Pl***@Pluto.com> wrote:
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


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.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #4
Thanks.
"Amit Khot" <am*******@hotmail.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.GetFiles ();
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.ToArray(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.GetFiles(string) method.

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

of type
DirectoryInfo

Help.

Thanks.
.

Nov 15 '05 #5

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

Similar topics

2
20193
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 =...
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...
8
1887
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
2370
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
6479
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
2588
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...
1
2544
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
11614
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
7234
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,...
0
7412
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...
1
7069
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...
0
7505
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
5652
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,...
1
5060
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...
0
3216
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...
0
1570
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 ...
1
775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.