Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

c#判断文件夹是否存在

作者:亡梦   发布日期:2025-05-28   浏览:29

using System;
using System.IO;

class Program
{
    static void Main()
    {
        // 定义文件夹路径
        string folderPath = @"C:\path\to\your\folder";

        // 判断文件夹是否存在
        if (Directory.Exists(folderPath))
        {
            Console.WriteLine("文件夹存在。");
        }
        else
        {
            Console.WriteLine("文件夹不存在。");
        }
    }
}

解释说明:

  1. 引入命名空间using System;using System.IO; 是必要的,因为我们需要使用 Console 类来输出信息,以及 Directory 类来检查文件夹是否存在。
  2. 定义文件夹路径:通过 string folderPath 变量定义要检查的文件夹路径。
  3. 判断文件夹是否存在:使用 Directory.Exists(folderPath) 方法来检查指定路径的文件夹是否存在。该方法返回一个布尔值,如果文件夹存在则返回 true,否则返回 false
  4. 输出结果:根据文件夹是否存在,输出相应的提示信息。

上一篇:c# zip

下一篇:c#判断字符串为空

大家都在看

c# 二进制

c# tcp client

c# type.gettype

c# sqlconnection

.net和c#

c#游戏开发

c#网络编程

c# rectangle

c# if else

c# rtsp

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站