两个硬盘和文件相关技巧
取系统的硬盘分区的盘符,用API函数:GetDriveType [DllImport("kernel32.dll", EntryPoint="GetDriveType")] public static extern int GetDriveType (string nDrive);调用:
string [] dirs = Environment.GetLogicalDrives(); //取得所有的盘符 foreach(string dir in dirs) { ?if ( GetDriveType(dir) == 3 ) //是硬盘 ?{ ??? //加到列表中 ?} } 判断文件夹是否是系统文件加或隐藏目录: 使用DirectoryInfo类的Attribute属性 DirectoryInfo [] subDirs = dir.GetDirectories(); //dir是DirectoryInfo 类的一个实例 foreach(DirectoryInfo subDir in subDirs) { ?? if ( subDir.Attributes.ToString().IndexOf("Hidden") < 0 || subDir.Attributes.ToString().IndexOf("System") < 0 ) ?{ ??... ?} }