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.

Table 13-5. Table 13-5
Method or PropertyDescription
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
AttributesGets the file attributes of a specified file
CreationTimeGets or sets the creation time for a file
DirectoryGets an instance of the parent directory
DirectoryNameReturns the full path name as a string
ExistsDetermines if a file exists
ExtensionReturns a string representation of a file's extension
FullNameReturns the complete path of a file or directory
LastAccessTimeReturns the last time the file was accessed
LengthReturns the number of bytes in a file
NameReturns 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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.