- Part 3
- Topic 3
Access files and folders by using the File System classes. (Refer System.IO namespace)
- File class and FileInfo class
- Directory class and DirectoryInfo class
- DriveInfo class and DriveType enumeration
- FileSystemInfo class and FileSystemWatcher class
- Path class
- ErrorEventArgs class and ErrorEventHandler delegate
- RenamedEventArgs class and RenamedEventHandler delegate
The File Class exposes static methods for creating, copying, moving, deleting and opening files and can create filestream objects while the FileInfo class provides instance methods for the same functions. See the resources if you are not familiar with using these classes.
The Directory Class exposes static methods for creating, moving and enumerating through directories while the Directory Info Class provides instance methods for the same functions. See the resources if you are not familiar with using these classes.
The DriveInfo Class is new to .Net 2.0 and exposes information about drives like Available space, drive format, drive type, IsReady, Name, RootDirectory, TotalFreeSpace, Total Space and the volume label. The Drive Type is an enum with seven members: CDRom, Fixed, Network, NoRootDirectory, Ram, Removable and unknown.
The FileSystemInfo class is the base class that both the FileInfo and DirectoryInfo classes derive from. It can represent either a file or a directory so use this class when parsing large amounts of files or directories.
The FileSystemWatcher Class listens to file system change notifications for files or directories and raises events.
The Path Class is used to perform operations on strings that contain file and path information. By passing a string with a path in into it to some of this classes static methods you can get information like the path root, filename and extension without having to parse the string yourself.
The ErrorEventHandler delegate is the method that will handle the error event for a FileSystemWatcher Object. The ErrorEventArgs are the argurments (like the Exception itself) that will be passed into the method handling the event.
The RenamedEventHandler delegate is the method that will handle the file renamed event for a FileSystemWatcher object. The RenamedEventArgs contain the argurments (old file path, new file path) that will be passed into the method handling the event.
Other Resources & Links: