|
private string GetDirectoryAttrib(string DirectoryName) { System.Diagnostics.Process p=new System.Diagnostics.Process(); string t1; if(Directory.Exists(DirectoryName)) { p.StartInfo.CreateNoWindow=true; p.StartInfo.UseShellExecute=false; p.StartInfo.RedirectStandardOutput=true; p.StartInfo.FileName="attrib"; p.StartInfo.Arguments=DirectoryName; p.Start(); p.WaitForExit(); t1=p.StandardOutput.ReadToEnd(); t1=t1.Substring(0,t1.IndexOf(DirectoryName)); t1=t1.Replace(" ",""); } else { t1=""; } return t1; } 利用DOS命令attrib返回文件夹的属性, 返回值里面含有S就是系统属性,H就是隐藏属性,R表示只读 上面代码有一个小问题就是如果文件夹名称中含有空格,attrib命令无法识别, 所以会报错。
|