开发者

Help with searching for files in C#

I am working on a search and replace console app to help out some people in my department. I am trying to have them input a file path and also the type of file they would like to search for. if they want to find txt files then it will find all txt files in a directory...stick these into an array and then process the files as needed. I am able to do the search and replace part.

I am new to C# and have a solution working in Python, b开发者_Python百科ut they want it more portable.


string path = @"C:\temp";
string searchPattern = "*.txt";
string[] files = Directory.GetFiles(path, searchPattern);
foreach (string f in files)
    Console.WriteLine(f);


You could always port it to IronPython if they are worried about .Net compatibility.


This question is really too broad, we aren't going to write the code for you.

However, here are some links to functionality common in this type of app:

Listing Files in a Directory:

http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=356

Reading and Writing Files:

http://www.csharp-station.com/HowTo/ReadWriteTextFile.aspx

Hope that is a good enough head start.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜