如何在 C# 中使用 directory 类?
C# 中的 Directory 类用于操作目录结构。它具有用于创建、移动、移除目录的方法。
以下是 Directory 类的一些方法。
| 序号 | 方法和描述 |
|---|---|
| 1 | CreateDirectory(String) 在指定的路径中创建所有目录和子目录 |
| 2 | Delete(String) 删除空的目录 |
| 3 | Exists(String) 给定路径是否引用现有的目录 |
| 4 | GetCreationTime(String) 获取目录的创建日期和时间。 |
| 5 | GetCurrentDirectory() 获取当前工作目录 |
| 6 | GetFiles(String) |
让我们了解 Directory 类中 GetFiles() 方法的使用。它显示指定目录中的所有文件。
示例
using System;
using System.IO;
class Program {
static void Main() {
// Get all files in the D directory
string[] arr = Directory.GetFiles(@"D:\");
Console.WriteLine("Files:");
foreach (string n in arr) {
Console.WriteLine(n);
}
}
}
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP