Xem mẫu
- Xử lý tập tin
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- Nội dung
Làm việc với hệ thống file và thư mục
Đọc và ghi file
Nén thông tin
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- Navigating the File System
Nhu cầu:
Làm sao biết được trên hệ thống có những ổ đĩa
nào?
Làm sao lấy được danh sách tập tin và thư mục
con của một thư mục nào đó?
Làm sao truy xuất được các thuộc tính của một tập
tin, thư mục?
Làm sao giám sát được sự thay đổi của một tập
tin, thư mục?
…
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- Navigating the File System
Các lớp hỗ trợ
DriveInfo class
DirectoryInfo class
FileInfo class
Path class
FileSystemWatcher class
File class
Directory class
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- Navigating the File System
DriveInfo class
Cung cấp các thông tin khác nhau về các drive
Thuộc tính
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- Navigating the File System
DriveInfo class
DriveType enum
Phương thức
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- Navigating the File System
FileSystemInfo class
Là lớp cơ sở của lớp FileInfo và DirectoryInfo
Thuộc tính
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- Navigating the File System
FileSystemInfo class
Phương thức
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- Navigating the File System
DirectoryInfo class
Cung cấp thông tin và các lệnh làm việc vớithư
mục
Thuộc tính
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- Navigating the File System
DirectoryInfo class
Phương thức
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- Navigating the File System
FileInfo class
Cung cấp thông tin và các lệnh làm việc với
file
Thuộc tính
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- Navigating the File System
FileInfo class
Phương thức
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- Navigating the File System
Path class
Thao tác với đường dẫn tới file, thư mục.
Phương thức
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- Navigating the File System
Path class
Phương thức
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- Navigating the File System
FileSystemWatcher class
Theo dõi các thay đổi liên quan tới thư mục và
các file chứa trong đó.
Thuộc tính
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- Navigating the File System
FileSystemWatcher class
Phương thức
Sự kiện
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- Navigating the File System
Làm sao biết được trên hệ thống có những ổ đĩa nào?
DriveInfo[] drives = DriveInfo.GetDrives();
foreach (DriveInfo drive in drives)
{
Console.WriteLine("Drive: {0}", drive.Name);
Console.WriteLine("Type: {0}",
drive.DriveType);
}
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- Navigating the File System
Làm sao lấy được danh sách tập tin và thư mục con của một
thư mục nào đó?
DirectoryInfo ourDir = new DirectoryInfo(@"c:\windows");
Console.WriteLine("Directory: {0}", ourDir.FullName);
foreach (FileInfo file in ourDir.GetFiles())
{
Console.WriteLine("File: {0}", file.Name);
}
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- Navigating the File System
Làm sao truy xuất được các thuộc tính của một
tập tin, thư mục?
FileInfo ourFile = new FileInfo(@"c:\boot.ini ");
if (ourFile.Exists)
{
Console.WriteLine("Filename : {0}",
ourFile.Name);
Console.WriteLine("Path : {0}",
ourFile.FullName);
}
CuuDuongThanCong.com https://fb.com/tailieudientucntt
- Navigating the File System
Làm sao giám sát được sự thay đổi của một tập tin, thư mục?
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = @"c:\";
watcher.Renamed += new
RenamedEventHandler(watcher_Renamed);
watcher.EnableRaisingEvents = true;
static void watcher_Renamed(object sender, RenamedEventArgs e)
{
Console.WriteLine("Renamed from {0} to {1}", e.OldFullPath,
e.FullPath);
}
CuuDuongThanCong.com https://fb.com/tailieudientucntt
nguon tai.lieu . vn