The FileInfo Class
When you create a new FileInfo object, you must associate this object with a file by passing a string representation of a filename to the FileInfo constructor. This filename can either represent an already existing file, or a non-existing file that you want to create. We will look at how you can create a new file with FileInfo later.
Suppose that C:\MyTestFiles\MyFairytale.txt is an already existing file. The following line (taken from line 10 in Listing 22.1)
FileInfo existingFile = new FileInfo(@"C:\MyTestFiles\MyFairytale.txt");
creates a FileInfo object called existingFile that represents the file MyFairytale.txt located in the C:\MyTestFiles directory.
Why Use @ in Front of Filenames?
Why does the previous line of source ... |
Get C# Primer Plus now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.