在C#中,可以使用Directory.Exists方法来判断文件夹是否存在。下面是一个示例代码:

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/hQcF 著作权归作者所有。请勿转载和采集!

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