根据文件存储路径判断类型

来源:百度知道 编辑:UC知道 时间:2024/06/30 01:43:44
求:现在可以得到一个文件的完整路径,在c#中如何判断这个文件所在是光盘还是硬盘。以及是第几块光驱的方法
那怎样判断所在光驱为物理光驱还是虚拟光驱呢?

string path = "d:\\index.html";
System.IO.DriveInfo di = new System.IO.DriveInfo(path.Substring(0, 1));
if (di.DriveType == System.IO.DriveType.CDRom)
{
MessageBox.Show("这个文件位于光驱上!");

//查找光驱索引
int chardr = (int)di.Name.ToUpper()[0];
int index = 0;
while (chardr >= 65)
{
System.IO.DriveInfo pd = new System.IO.DriveInfo(((char)chardr).ToString());
if (pd.DriveType == System.IO.DriveType.CDRom) { index++; }
chardr--;
}

if (index == 0)
{
MessageBox.Show("本机只有一块光驱!");
}
else
{
MessageBox.Show("这是第 " + index + " 块光驱!");
}
}
else
{
MessageBox.Show("这个文件不在光驱上!");
}

---------------
物理光驱还是虚拟光驱很难判断的,毕竟是驱动层虚拟出来的,也不好识别。要是这个很容易判断的话,那么多光盘版的游戏就没法用虚拟光驱变成硬盘版啦。