Thursday, 9 August 2012

File System Classes

Inside the System.IO namespace are a set of classes used to navigate and manipulate files, directories, and drives. The file system classes are separated into two types of clasees: informational and utility. Most of the informational classes derive from the FileSystemInfo base class. These classes expose all the system information about file system objects- specifically, files, directories, and drives. These classes are named FileInfo and DirectoryInfo. The utility classes provide static methods to perform certain operations on file system objects such as files, directories and file system paths.

File SystemInfo Class

The FileSystemInfo class provides the basic functionality for all informational file system classes.Various properties are:
  • Attributes: Gets or sets FileAttributes of the current file or directory.
  • Exists: Determine whether the file or directory exists .
  • FullName: Gets the full path to the file or directory.
  • Name: Gets the simple name for the file or directory.
Various methods of FileSystemInfo are:
  • Delete: Removes the file or directory from the file system.
  • Refresh: Updates the data in the class with the most current information from the file system.

FileInfo Class

The FileInfo class provides the basic functionality to access and manipulate a single file in the file system. Various FileInfo properties are:
  • Directory: Gets the DirectoryInfo object that represents the directory that this file is stored within.
  • DirectoryName: Gets the name of the directory that this file is stored within.
FileInfo methods are:
  • CopyTo: Makes a copy of the file in a new location.
  • Create: Creates a file based on the current file information.
  • MoveTo: Moves the file to a new location.
  • Open: Opens the file with special privileges like read, read/write, etc. 



No comments:

Post a Comment