您的位置:首页 > 编程语言 > C#

做练习时写了一个调用DOS命令删文件夹及子目录和文件的C#程序

2007-11-23 14:46 447 查看
  public void delFIlesandDir(string path,string dirname)
        {
            DirectoryInfo dinfo = new DirectoryInfo(path);
           

            try
            {
                foreach (DirectoryInfo d in dinfo.GetDirectories())
                {
                    if (d.Name == dirname)
                    {
                         Process p = new Process();
                        p.Star
4000
tInfo.FileName = "cmd.exe";
                        p.StartInfo.UseShellExecute = false;
                        p.StartInfo.RedirectStandardInput = true;
                        p.StartInfo.RedirectStandardOutput = true;
                        p.StartInfo.CreateNoWindow = true;
                        p.Start();
                        p.StandardInput.WriteLine("attrib *.* -r -h -a -s /S /D");
                       
                        p.StandardInput.WriteLine(@"rd "+@d.FullName+" /s /q");
                       // p.WaitForExit(3000);
                        p.StandardInput.WriteLine("exit");
                      
                       
                        p.Close();
                    }else if (d.GetDirectories().Length > 0)
                    {
                        delFIlesandDir(d.FullName,dirname);
                    }
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        } 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  dos c# exception string path
相关文章推荐