TAILIEUCHUNG - C# Bible 2002 phần 8

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 .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.