473,508 Members | 2,373 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Directory.GetFiles() dosn't accept *.txt as search pattern

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
{
public static void Main()
{
try
{

string[] dirs = Directory.GetFiles(@"c:\", "*.txt");
Console.WriteLine("The number of files starting with c is {0}.",
dirs.Length);
foreach (string dir in dirs)
{
Console.WriteLine(dir);
}
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}", e.ToString());
}
}
}
Nov 16 '05 #1
2 9674
"ALI-R" <al*@microsoft.com> wrote in
news:uU**************@TK2MSFTNGP11.phx.gbl:
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
{
public static void Main()
{
try
{

string[] dirs = Directory.GetFiles(@"c:\", "*.txt");
Console.WriteLine("The number of files starting with
c is {0}.",
dirs.Length);
foreach (string dir in dirs)
{
Console.WriteLine(dir);
}
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}",
e.ToString());
}
}
}


Your code works on my machine.

What error message are you getting? Or is Directory.GetFiles simply
not returning any files?

(Realize that Directory.GetFiles is not recursive. It only looks for
files in the specified folder, and will not search any child
folders).

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 16 '05 #2
thank you very much .I made a mistake passing the right path to it.it is
working fine now

I appreciate your help
"Chris R. Timmons" <crtimmons@X_NOSPAM_Xcrtimmonsinc.com> wrote in message
news:Xn**********************************@207.46.2 48.16...
"ALI-R" <al*@microsoft.com> wrote in
news:uU**************@TK2MSFTNGP11.phx.gbl:
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
{
public static void Main()
{
try
{

string[] dirs = Directory.GetFiles(@"c:\", "*.txt");
Console.WriteLine("The number of files starting with
c is {0}.",
dirs.Length);
foreach (string dir in dirs)
{
Console.WriteLine(dir);
}
}
catch (Exception e)
{
Console.WriteLine("The process failed: {0}",
e.ToString());
}
}
}


Your code works on my machine.

What error message are you getting? Or is Directory.GetFiles simply
not returning any files?

(Realize that Directory.GetFiles is not recursive. It only looks for
files in the specified folder, and will not search any child
folders).

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/

Nov 16 '05 #3

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

Similar topics

2
3625
by: Amy L. | last post by:
I am working on some code that will be used in a Windows Service that will monitor specific files in a queue. I would like to get an integer value of the amount of specfic files in a directory. ...
4
1766
by: Mullin Yu | last post by:
e.g. c:\test doc1.txt doc1.pdf doc2.txt doc2.pdf doc3.txt doc4.pdf doc5.txt doc5.pdf
2
5953
by: John Smith | last post by:
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.GetFiles(sDir, "*.doc*.dot"); However, this...
2
26893
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...
1
5631
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:...
2
1888
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...
4
7912
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...
1
1664
by: andrew | last post by:
Hi I have the following script, which lists files within a specified web directory (as long as they are valid extension types). It works, but I would like the file names to be links (i.e. with...
9
4614
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...
0
7115
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...
0
7377
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...
0
7489
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
5624
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
5047
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
3191
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
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1547
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
762
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.