To obtain information about a file, we must create a new FileInfo object by specifying the path to the file and use the FileInfo object to retrieve information about the file.
Example code:
FileInfo fi = new FileInfo(@"C:\file.txt"); if(fi.Exists) { Console.WriteLine("Filename : {0}", fi.Name); Console.WriteLine("Path : {0}", fi.FullName); }
The Exists property tells us if the file exists physically.
Tags: file handling, info