473,594 Members | 2,757 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Directory.GetFi les search param

Hello all:

I am trying to search for more than one extension in a directory at the
same time with the following code:

string[] files = Directory.GetFi les(sDir, "*.doc*.dot ");

However, this does not work nor does something like this:

string[] files = Directory.GetFi les(sDir, "*.doc, *.dot");

I can search for each individually but that is rather inefficient. Is
there a way to search for multiple extensions at once?

Thanks,

- John -
Nov 16 '05 #1
2 5969
sure, "*.*" and then in the loop check the extension of the file against
those you are interested in (you can put those extensions in a string and
use indexof but have a good look at what getfiles does, it might surprise
you)
"John Smith" <oh******@hotma il.com> wrote in message
news:Os******** ******@TK2MSFTN GP10.phx.gbl...
Hello all:

I am trying to search for more than one extension in a directory at the
same time with the following code:

string[] files = Directory.GetFi les(sDir, "*.doc*.dot ");

However, this does not work nor does something like this:

string[] files = Directory.GetFi les(sDir, "*.doc, *.dot");

I can search for each individually but that is rather inefficient. Is
there a way to search for multiple extensions at once?

Thanks,

- John -

Nov 16 '05 #2
Get Files will not do what you want. Why not write a method that takes a
variable number of string arguments that are the extensions, retrieves and
merges the results from calls to GetFiles on each string. That should be
trivial.

--

Chris Rolon

This posting is provided "AS IS" with no warranties, and confers no rights.

"Joep" <St***@DeStoep. nl> wrote in message
news:42******** *************** @news.xs4all.nl ...
sure, "*.*" and then in the loop check the extension of the file against
those you are interested in (you can put those extensions in a string and
use indexof but have a good look at what getfiles does, it might surprise
you)
"John Smith" <oh******@hotma il.com> wrote in message
news:Os******** ******@TK2MSFTN GP10.phx.gbl...
Hello all:

I am trying to search for more than one extension in a directory at the
same time with the following code:

string[] files = Directory.GetFi les(sDir, "*.doc*.dot ");

However, this does not work nor does something like this:

string[] files = Directory.GetFi les(sDir, "*.doc, *.dot");

I can search for each individually but that is rather inefficient. Is
there a way to search for multiple extensions at once?

Thanks,

- John -


Nov 16 '05 #3

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

Similar topics

2
9682
by: ALI-R | last post by:
I am using the follwoing code to get all files which have txt as an extension but I get an error that your search pattern is not correct.it seems this fuction dosn't accept "*.txt" as search pattern. Is there somebody can help me? using System; using System.IO; class Test
2
26905
by: Alphonse Giambrone | last post by:
Is there a way to use multiple search patterns when calling Directory.GetFiles. For instance Directory.GetFiles("C:\MyFolder", "*.aspx") will return all files with the aspx extension. But what if I wanted all files with either an aspx OR htm extension? Any way to get that without calling the method twice? -- Alphonse Giambrone Email: a-giam at customdatasolutions dot us
1
5636
by: brian | last post by:
I am using the Directory.GetFiles class and am having problems with the overloaded version. I want to search files. I can use the following and it works fine: Directory.GetFiles(Path, k) Path: c:/Test/ k: 3 It will query all files in the test directory with a file that is named 3.
2
1896
by: OpticTygre | last post by:
I have a directory of 27 files. The files end in either 1.txt, 2.txt, 3.txt, or 4.txt. If I say: For Each filename As String In Directory.GetFiles("C:\TSA\DOWNLOADS\TRX\PERFORMANCE_DATA\DOWNLOAD\", "*1.TXT") Debug.WriteLine(filename) Next
1
1885
by: Hawk | last post by:
I was writing my own wildcard compare algorithm and making a custom GetFiles routine when I came across what I think is a bug in .net's own GetFiles. My routine was coming up with different results than GetFiles so naturally I thought it was my routine that was bugged but when I investigated it the results from my algorithm where exactly what I would expect. call: System.IO.Directory.GetFiles("d:\\windows\\system32\\", "*ae?*.*",...
18
23775
by: Arthur | last post by:
Hi All, I would like to get the name of the user given their networkID, is this something Active Directory would be useful for?(For intranet users) If so, can you please point me to some sample code/examples? Thanks in advance, Arthur
4
7926
by: John Dann | last post by:
Is there a way to limit the search pattern for Directory.Getfiles to an exact number of characters. For example I want to see all the files fitting the pattern "*.abc" but excluding "*.abcd". The default behaviour seems to include .abcd when searching for just"*.abc", which I suppose is logical in one way, but not what I want. JGD
9
4618
by: Julie Smith | last post by:
Hi, Is it just me or does the search pattern parameter in Directory.GetFiles() have a problem with the '?' character? '*.*' works to find all files, but '?.*' does not work to find all files that have only a one letter (and infinite extension size) filename. In fact, it seems to act the same as '*.*'... Is this by design?
2
6668
by: Alex | last post by:
Hello, I'm creating a program to parse a directory and all files within that directory (including subdirectories), but 'directoryinfo' only parses the current directory. Is it possible to have it process all files within subdirectories as well? Thanks -- Alex
0
8255
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
8374
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...
1
8010
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
5413
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
3868
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3903
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2389
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
1
1486
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1217
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.