Directory operations
Imagine having a file system with one root folder. All files on your drive are stored there. You would have a tough time finding all your files. Luckily, operating systems all support the notion of folders or directories. The CLR helps us by giving us two classes to work with paths, folders, and directories: Path and Directory.
The Path class
Path
is a class that has helper methods for dealing with paths. With Path
, I mean the string that denotes the name of a directory. You should use the Directory
class when dealing with the actual directory and files.
We have already seen the Path
class in previous samples. I used it to get a temporary filename and the name of the Documents
folder. I also used it to combine a path and a filename to avoid dealing with path separators myself.
There are quite a few handy methods and properties in the Path
class. You can see some of the most-used ones in the following table.