Anant Patil Anant Patil - 7 months ago 34
C# Question

How to search system files and list them in windows 7 and above using c#?

I want to search all systems files on windows 7 and above versions of windows.

Besides I want to list them in a txt file.

Can somebody please provide me a code snippet including exception handling for UAC?

Thank you in advance.


You can use it

Get files from directory

using System.IO;

string[] filePaths = Directory.GetFiles(@"c:\MyDir\");

Get files from directory (with specified extension)

    string[] filePaths = Directory.GetFiles(@"c:\MyDir\", "*.bmp");
// returns:
// "c:\MyDir\my-car.BMP"

Get files from directory (including all subdirectories)

    string[] filePaths = Directory.GetFiles(@"c:\MyDir\", "*.bmp",
// returns:
// "c:\MyDir\my-car.BMP"
// "c:\MyDir\Friends\james.BMP"

How save array like .txt file? Like this.

using (FileStream fs = File.Open("scores.txt"))
    StreamWriter sw = new StreamWriter(fs);