Tham khảo tài liệu 'c# 2005 programmer’s reference - chapter 11', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 184 CHAPTER 11 Files and Serialization static void Main string args if 1 Usage ShowFileSecurity filename return string filename args 0 FileInfo info new Filelnfo filename Filesecurity security ShowSecurity security private static void ShowSecurity FileSecurity security AuthorizationRuleCollection coll true true typeof NTAccount foreach FileSystemAccessRule rule in coll IdentityReference 0 Access control type 0 Rights 0 Inherited 0 You can run the program from the command line like this D code ch11 ShowFileSecurity bin Debug It produces output similar to the following IdentityReference Ben-Desktop Ben Access control type Allow Rights FullControl Inherited True IdentityReference NT AUTHORITY SYSTEM Access control type Allow Rights FullControl Inherited True Enumerate Drives 185 IdentityReference BUILTIN Administrators Access control type Allow Rights FullControl Inherited True Check for File and Directory Existence Scenario Problem You need to check if a file or directory exists before attempting to use it. Solution This snippet uses the static Exists methods on File and Directory to check for existence string target @ D Files if target File 0 exists target else if target Directory 0 exists target Enumerate Drives Scenario Problem You want to get a list of all drives installed on the system. Solution The Driveinfo class provides static methods to retrieve this information. DriveInfo drives foreach DriveInfo info in drives Name 0 RootDirectory 1 DriveType 0 IsReady 0 you ll get an .