C# 程序检查目录是否存在
使用 Directory.Exists 方法检查目录是否存在。
假设你需要检查以下目录是否存在 −
C:\Amit
为此,请使用 Exists() 方法 −
if (Directory.Exists("C:\Amit")) {
Console.WriteLine("Directory Amit Exist!");
}以下为完整代码 −
示例
using System.IO;
using System;
public class Program {
public static void Main() {
if (Directory.Exists("C:\Amit")) {
Console.WriteLine("Directory Amit Exist!");
} else {
Console.WriteLine("Directory Amit does not exist!");
}
}
}输出
Directory Amit does not exist!
广告
数据结构
网络
关系数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP