This tutorial explains how to carry out many common tasks relating to the accessing and manipulating a server file system, including listing files and directories, checking for the existence of a specific file or directory, reading and writing text to text files, copying, moving and deleting files and directories. You will also be shown how to obtain statistics of directories and files such as file size and modified dates. By the time you have worked through this article you will be more knowledgeable about file system access and manipulation using the powerful classes provided within the .NET Framework.
The tutorial covers the following subjects:
- Writing text to a file
- Reading text from a file
- Finding out if a file or directory exists
- Renaming a file or directory
- Copying and moving a file or directory
- Deleting a file or directory
- Listing the contents of a directory
- A hierarchal listing example
- Common problems and errors
We end the tutorial with an example of displaying the contents of a directory using a recursive routine to show the hierarchy of its contents in much the same manner as a tree control would display them.