做练习时写了一个调用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());
}
}
{
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());
}
}
相关文章推荐
- C#中调用dos命令修改文件名称
- dos命令—将多个文件夹下的多个txt文件合并成为一个txt文件
- JAVA与C#程序调用DOS命令
- 在asp.net下调用dos命令 :我用的是调用重定向写入一个文件
- C#中利用process类调用外部程序以及执行dos命令
- 做一个bat文件,如何把远程电脑一个文件夹下的文件用DOS命令COPY到本机上
- C#中利用process类调用外部程序以及执行dos命令 - ASP.NET
- 程序中调用一个可执行文件,防止小部分程序down掉导致整个程序down掉
- 续:C# 趣味小程序(4)——遍历特定目录及其子目录 (应用实例,压缩指定目录下的所有文件)
- 编写一个程序,能在当前目录以及当前目录的所有子目录下查找文件名包含指定字符串的文件,并打印出相对路径。
- DOS命令 递归删除子目录下的各同名文件夹
- 如何用c#打开文件夹并选择文件夹内的一个文件 open folder and select file
- c#中调用cmd命令执行批处理文件
- C#调用系统注册程序打开pdf文件
- 收藏——在C#使用SHGetFileInfo获取(管理)文件或者文件夹图标(C#封装Win32函数的一个例子)
- 如何用C#编写程序监测某个文件夹内是否有文件进行了增,删,改的动作?
- (二)一个工作任务引起的乱战——C++程序编译为dll,让C#调用
- C#程序调用cmd执行命令
- 用c#实现 统计一个文件夹中的文件的个数 并用 FOR循环 依次读取文件的文件名
- C#将制定文件夹下的PDF文件合并成一个并输出至指定路径