This is a C# Program to search directories and list files.
Problem Description
This C# Program Searches Directories and List Files.
Problem Solution
Here the particular given directory is searched and all the files are listed.
Program/Source Code
Here is source code of the C# Program to Search Directories and List Files. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
/* * C# Program to Search Directories and List Files */ using System; using System.IO; class Program { static void Main() { string[] Dirfile = Directory.GetFiles("C:\\sri\\","*.*", SearchOption.AllDirectories); foreach (string file in Dirfile) { Console.WriteLine(file); } Console.Read(); } }
Program Explanation
This C# program is used to search directories and list files. Here the particular given directory is searched and all the files are listed. Using foreach loop print the directories and list files.
advertisement
advertisement
Runtime Test Cases
The List of Files in the Directory are : C:\sri\message.txt C:\sri\srip.txt C:\sri\test.txt
Sanfoundry Global Education & Learning Series – 1000 C# Programs.
If you wish to look at all C# Programming examples, go to 1000 C# Programs.
Next Steps:
- Get Free Certificate of Merit in C# Programming
- Participate in C# Programming Certification Contest
- Become a Top Ranker in C# Programming
- Take C# Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Related Posts:
- Buy MCA Books
- Practice MCA MCQs
- Buy C# Books
- Buy Computer Science Books
- Practice Computer Science MCQs