检查DirectoryInfo.FullName是特殊的文件夹 [英] Check if DirectoryInfo.FullName is special folder
本文介绍了检查DirectoryInfo.FullName是特殊的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的目标是检查,如果DirectoryInfo.FullName是特殊文件夹之一。
My goal is to check, if DirectoryInfo.FullName is one of the special folders.
下面是我在做什么这个(检查directoryInfo.FullName到每一个特殊的文件夹,如果他们是平等的):
Here is what I'm doing for this (Check directoryInfo.FullName to each special folder if they are equal):
DirectoryInfo directoryInfo = new DirectoryInfo("Directory path");
if (directoryInfo.FullName == Environment.GetFolderPath(Environment.SpecialFolder.Windows) ||
directoryInfo.FullName == Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles ||)
...
...
)
{
// directoryInfo is the special folder
}
但也有许多特殊的文件夹(饼干,的ApplicationData,InternetCache等)。有什么办法能够更有效地完成这项任务?
But there are many special folders (Cookies, ApplicationData, InternetCache, etc.). Is there any way to do this task more efficiently?
感谢。
推荐答案
试试这个下面的代码:
bool result = false;
DirectoryInfo directoryInfo = new DirectoryInfo("Directory path");
foreach (Environment.SpecialFolder suit in Enum.GetValues(typeof(Environment.SpecialFolder)))
{
if (directoryInfo.FullName == Environment.GetFolderPath(suit))
{
result = true;
break;
}
}
if (result)
{
// Do what ever you want
}
希望这帮助。
这篇关于检查DirectoryInfo.FullName是特殊的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文