Upload
raghu-nath
View
74
Download
4
Tags:
Embed Size (px)
Citation preview
System Information
System Information Get Drive information in current system Get info of specific Drive
Available Free Space DriveFormat IsReady Name RootDirectory TotalFreeSpace TotalSize VolumeLabel List Drive List Sub folders List Files
System.IO.FileInfo Provides properties and instance methods for the creation,
copying, deletion, moving, and opening of files, and aids in the creation of FileStream objects. This class cannot be inherited.
System.IO.DirectoryInfo Exposes instance methods for creating, moving, and enumerating
through directories and subdirectories. This class cannot be inherited.
System.IO.DriveInfo Provides access to information on a drive.
System.IO.Directory Exposes static methods for creating, moving, and enumerating
through directories and subdirectories. This class cannot be inherited.
Public Attributes Gets or sets the attributes for the current file or
directory. (Inherited from FileSystemInfo.)Public CreationTime
Gets or sets the creation time of the current file or directory. (Inherited from FileSystemInfo.)
Public propertyCreationTimeUtc Gets or sets the creation time, in coordinated
universal time (UTC), of the current file or directory. (Inherited from FileSystemInfo.)
Public Directory Gets an instance of the parent directory.
Public DirectoryName Gets a string representing the directory's full
path.Public Exists
Gets a value indicating whether a file exists. (Overrides FileSystemInfo.Exists.)
Public Extension Gets the string representing the extension part
of the file. (Inherited from FileSystemInfo.)Public FullName
Gets the full path of the directory or file. (Inherited from FileSystemInfo.)
Public propertyIsReadOnly Gets or sets a value that determines if the
current file is read only.
Public LastAccessTime Gets or sets the time the current file or
directory was last accessed. (Inherited from FileSystemInfo.)
Public propertyLastAccessTimeUtc Gets or sets the time, in coordinated universal
time (UTC), that the current file or directory was last accessed. (Inherited from FileSystemInfo.)
Public LastWriteTime Gets or sets the time when the current file or
directory was last written to. (Inherited from FileSystemInfo.)
Public propertyLastWriteTimeUtc Gets or sets the time, in coordinated universal
time (UTC), when the current file or directory was last written to. (Inherited from FileSystemInfo.)
Public Length Gets the size, in bytes, of the current file.
Public Name Gets the name of the file. (Overrides
FileSystemInfo.Name.)
DirectoryInfo Class
Exposes instance methods for creating, moving, and enumerating through directories and subdirectories. This class cannot be inherited.
Properties
Public property Attributes Gets or sets the attributes for the current file or
directory. (Inherited from FileSystemInfo.)Public property CreationTime
Gets or sets the creation time of the current file or directory. (Inherited from FileSystemInfo.)
Public propertyCreationTimeUtc Gets or sets the creation time, in coordinated
universal time (UTC), of the current file or directory. (Inherited from FileSystemInfo.)
Public Exists Gets a value indicating whether the directory
exists. (Overrides FileSystemInfo.Exists.)Public Extension
Gets the string representing the extension part of the file. (Inherited from FileSystemInfo.)
Public FullName Gets the full path of the directory or file.
(Inherited from FileSystemInfo.)
Public LastAccessTime Gets or sets the time the current file or
directory was last accessed. (Inherited from FileSystemInfo.)
Public LastAccessTimeUtc Gets or sets the time, in coordinated universal
time (UTC), that the current file or directory was last accessed. (Inherited from FileSystemInfo.)
Public LastWriteTime Gets or sets the time when the current file or
directory was last written to. (Inherited from FileSystemInfo.)
Public propertyLastWriteTimeUtc Gets or sets the time, in coordinated universal
time (UTC), when the current file or directory was last written to. (Inherited from FileSystemInfo.)
Public Name Gets the name of this DirectoryInfo instance.
(Overrides FileSystemInfo.Name.)Public Parent
Gets the parent directory of a specified subdirectory.Public Root
Gets the root portion of the directory.
System.IO.DriveInfo
Public propertyAvailableFreeSpace Indicates the amount of available free space on
a drive, in bytes.Public propertyDriveFormat
Gets the name of the file system, such as NTFS or FAT32.
Public propertyDriveType Gets the drive type, such as CD-ROM,
removable, network, or fixed.
Public propertyIsReady Gets a value that indicates whether a drive is
ready.Public propertyName
Gets the name of a drive, such as C:\.Public propertyRootDirectory
Gets the root directory of a drive.
Public propertyTotalFreeSpace Gets the total amount of free space available on
a drive, in bytes.Public propertyTotalSize
Gets the total size of storage space on a drive, in bytes.
Public propertyVolumeLabel Gets or sets the volume label of a drive.
Methods DriveInfo and Example
GetDrives()Retrieves the drive names of all logical drives
on a computer.
Directory Class
Methods Delete(String)
Deletes an empty directory from a specified path. Exists()
Determines whether the given path refers to an existing directory on disk.
GetAccessControl(String) Gets a DirectorySecurity object that encapsulates the
access control list (ACL) entries for a specified directory GetCurrentDirectory()
Returns the names of subdirectories (including their paths) in the specified directory.
Example of Drive Info
public static void Main() { DriveInfo[] allDrives = DriveInfo.GetDrives();
foreach (DriveInfo d in allDrives) { Console.WriteLine("Drive {0}", d.Name); Console.WriteLine(" File type: {0}", d.DriveType); if (d.IsReady == true) { Console.WriteLine(" Volume label: {0}", d.VolumeLabel); Console.WriteLine(" File system: {0}", d.DriveFormat); Console.WriteLine( " Available space to current user:{0, 15} bytes", d.AvailableFreeSpace);
Console.WriteLine( " Total available space: {0, 15} bytes", d.TotalFreeSpace);
Console.WriteLine( " Total size of drive: {0, 15} bytes ", d.TotalSize); } } System.Console.ReadLine(); }
Drive C:\ File type: Fixed Volume label: Windows File system: NTFS Available space to current user: 135662944256 bytes Total available space: 135662944256 bytes Total size of drive: 320070479872 bytesDrive D:\ File type: CDRomDrive Q:\ File type: Fixed
Example of File infoTotal PhysicalMemory example