21
System Information

8.C#

Embed Size (px)

Citation preview

Page 1: 8.C#

System Information

Page 2: 8.C#

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

   

Page 3: 8.C#

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.

Page 4: 8.C#

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.)

Page 5: 8.C#

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.)

Page 6: 8.C#

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.

Page 7: 8.C#

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.)

Page 8: 8.C#

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.)

Page 9: 8.C#

DirectoryInfo Class

Exposes instance methods for creating, moving, and enumerating through directories and subdirectories. This class cannot be inherited.

Properties

Page 10: 8.C#

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.)

Page 11: 8.C#

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.)

Page 12: 8.C#

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.)

Page 13: 8.C#

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.

Page 14: 8.C#

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.

Page 15: 8.C#

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.

Page 16: 8.C#

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.

Page 17: 8.C#

Methods DriveInfo and Example

GetDrives()Retrieves the drive names of all logical drives

on a computer.

Page 18: 8.C#

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.

Page 19: 8.C#

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(); }

Page 20: 8.C#

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

Page 21: 8.C#

Example of File infoTotal PhysicalMemory example