13.3. FileInfo Class
In Listing 13-2, I commented out a statement that uses the FileInfo class. This class provides a lot of details about the files you find on the system. Some of the more important properties and methods are presented in Table 13-5.
Method or Property | Description |
---|---|
AppendText() | Appends text for the current FileInfo object using a StreamWriter |
CopyTo() | Copies an existing file to a new file |
Create() | Creates a new file |
CreateText() | Creates a StreamWriter object that writes a new text file |
Delete() | Deletes a file |
Equals() | Determines if two FileInfo objects are equal |
MoveTo() | Moves a file to a new location with the option to rename it |
Open() | Opens a file with various read/write privileges |
Replace() | Replaces a specified file with contents of current FileInfo file |
Attributes | Gets the file attributes of a specified file |
CreationTime | Gets or sets the creation time for a file |
Directory | Gets an instance of the parent directory |
DirectoryName | Returns the full path name as a string |
Exists | Determines if a file exists |
Extension | Returns a string representation of a file's extension |
FullName | Returns the complete path of a file or directory |
LastAccessTime | Returns the last time the file was accessed |
Length | Returns the number of bytes in a file |
Name | Returns the name of the current file |
The tables and their associated methods and properties should give you enough information about directories and files for you to manipulate them in your programs. I draw on several of these properties and methods later ...
Get Beginning C# 3.0 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.