去除文件只读属性、判断文件夹及文件的隐藏属性
if (System.IO.File.GetAttributes(filePath).ToString().IndexOf("ReadOnly") != -1)//去除文件只读属性 { File.SetAttributes(filePath, FileAttributes.Normal); }
string[] folders = Directory.GetDirectories(path);
foreach (string fo in folders)
{
DirectoryInfo di = new DirectoryInfo(fo);
if ((di.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)//文件夹不是隐藏的 { ...... }
}
string[] files = Directory.GetFiles(path); foreach (string f in files) { FileInfo fi = new FileInfo(f); if ((fi.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden) { } }
欢迎交流,一起进步