在C#中,你可以使用Directory.Exists方法来判断文件夹是否存在。该方法的签名如下:

public static bool Exists(string path);

其中,path参数是文件夹的路径。

以下是一个示例:

using System;
using System.IO;

class Program
{
    static void Main()
    {
        string folderPath = @"C:\MyFolder";

        if (Directory.Exists(folderPath))
        {
            Console.WriteLine("文件夹存在");
        }
        else
        {
            Console.WriteLine("文件夹不存在");
        }
    }
}

在上述示例中,我们首先定义了一个文件夹路径folderPath,然后使用Directory.Exists方法来判断该文件夹是否存在。如果存在,就输出“文件夹存在”,否则输出“文件夹不存在”

C#中判断文件夹是否存在

原文地址: https://www.cveoy.top/t/topic/ieHD 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录