Chapter 19 File System Objects

What’s in This Chapter

  • Directory and File classes
  • DriveInfo, DirectoryInfo, and FileInfo classes
  • FileSystemWatcher and Path classes
  • Managing the recycle bin Downloads for This Chapter

Please note that all the code examples for this chapter are available as a part of this chapter’s code download on the book’s website at on the Download Code tab.

The preceding chapter described stream classes that you can use to read and write files. (It also described the File class, which isn’t a stream class but is just too useful to ignore when you use streams.) Those classes are handy but even those like StreamWriter that work at the highest levels still represent only the contents of files. They don’t give you any tools for working with the filesystem. Some of their methods can create a file, but they cannot rename or delete a file, or create or delete a directory.

This chapter describes classes that represent the filesystem. They allow you to create, rename, and delete files and directories. The final section in this chapter explains another important file-managing topic: how to use the recycle bin (wastebasket).

Filesystem Permissions

A program cannot perform a task unless the user has the appropriate permissions. Although this is true ...

Get C# 5.0 Programmer's Reference now with O’Reilly online learning.

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