Tham khảo tài liệu 'c# bible 2002 phần 8', 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ả | Listing 24-10 Use the FileInfo Class to Delete Files with Ease using System using namespace rm class Classi static void Main string args string cla if O 1 FileInfo fi new FileInfo cla 1 File cla 1 Attributes File Deleted. else Usage rm filename As with the previous examples you are storing the command-line arguments within a string array. If that array does not contain the correct number of elements you simply display a usage message and exit. Tip By using the Delete method of the FileSystemInfo class you can delete directories as well as files. After calling the Delete method of the FileInfo class you can display the filename and its attributes to the user indicating that it was deleted. Using the Attributes property you can safely determine before the file is deleted if it has a Read-Only attribute set. If so you can prompt the user and or remove the Read-Only attribute using the Attributes property along with the FileAttributes enumerator. After your program is compiled go to a command prompt and test it. Simply type rm followed by the filename to delete. The results should resemble those in Figure 24-6. Moving files The MoveTo method of the FileInfo class actually encapsulates two different methods CopyTo and Delete . After a file is copied to the appropriate filename or directory MoveTo simply deletes the file much as the Delete method does. The following sample application accepts two command-line arguments Source Filename and Destination Filename. After the file is moved the program displays when the file was actually created and where the file was moved to. Neither of these outputs has a practical use except to demonstrate how the certain attributes can be obtained such as the creation time using the CreationTime property. Figure 24-6 The Delete method of the FileInfo class shows the attributes .