您的位置:首页 >> 编程开发 >> .NET >> 其它 >> 正文
其它 RSS
 

调用attrib命令查看文件夹属性。

http://www.rdxx.com 05年07月27日 21:50 CSDN 我要投稿

关键词: 属性 , 文件夹 , 调用 , 命令 , 文件

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命令无法识别,
所以会报错。



 
 
标签: 属性 , 文件夹 , 调用 , 命令 , 文件 打印本文
 
 
  热点搜索
 
 
 



Valid XHTML 1.0 Transitional
Copyright ©2005 - 2008 Rdxx.Com,All Rights Reserved
收藏本页
收藏本站