Common I/O Tasks
The System.IO namespace provides several classes that allow for various actions, such as reading and writing, to be performed on files, directories, and streams. For more information, see File and Stream I/O.
|
To do this... |
See the example in this topic... |
|---|---|
|
Create a text file |
File.CreateText method FileInfo.CreateText method File.Create method FileInfo.Create method |
|
Write to a text file |
|
|
Read from a text file |
|
|
Append text to a file |
How to: Open and Append to a Log File File.AppendText method FileInfo.AppendText method |
|
Rename or move a file |
File.Move method FileInfo.MoveTo method |
|
Delete a file |
File.Delete method FileInfo.Delete method |
|
Copy a file |
File.Copy method FileInfo.CopyTo method |
|
Get the size of a file |
FileInfo.Length property |
|
Get the attributes of a file |
File.GetAttributes method |
|
Set the attributes of a file |
File.SetAttributes method |
|
Determine whether a file exists |
File.Exists method |
|
Read from a binary file |
|
|
Write to a binary file |
|
|
Retrieve a file name extension |
Path.GetExtension method |
|
Retrieve the fully qualified path of a file |
Path.GetFullPath method |
|
Retrieve the file name and extension from a path |
Path.GetFileName method |
|
Change the extension of a file |
Path.ChangeExtension method |
|
To do this... |
See the example in this topic... |
|---|---|
|
Create a directory |
Directory.CreateDirectory methodFileInfo.Directory property |
|
Create a subdirectory |
|
|
Rename or move a directory |
Directory.Move method DirectoryInfo.MoveTo method |
|
Copy a directory |
|
|
Delete a directory |
Directory.Delete method DirectoryInfo.Delete method |
|
See the files and subdirectories in a directory |
|
|
Find the size of a directory |
System.IO.Directory class |
|
Determine whether a directory exists |
Directory.Exists method |