【发布时间】:2026-01-26 08:30:02
【问题描述】:
我想检查特定文件夹是否存在于 c# 中的文件夹中。 目前我正在使用以下代码。
string currentPath = Directory.GetCurrentDirectory();
foreach (string subDir in Directory.GetDirectories(currentPath))
{
if (subDir == currentPath + @"\Database") // if "Database" folder exists
{
dbinRoot = true;
}
}
if (dbinRoot == true)
{
currentPath = currentPath + @"\Database\SMAStaff.accdb";
}
else
{
for (int i = 0; i < 2; i++)
{
currentPath = currentPath.Remove(currentPath.LastIndexOf("\\"));
}
currentPath = currentPath + "\\Database\\SMAStaff.accdb";
}
我想知道是否有更好的方法来做到这一点???
【问题讨论】:
标签: c# directory datadirectory