[C#]使用CMD命令删除文件函数
来源:互联网 发布:java邮箱验证基本思路 编辑:程序博客网 时间:2024/05/18 02:00
点击查看全文
#region 使用CMD命令删除文件函数 /// <summary> /// 使用CMD命令删除文件函数 /// </summary> /// <param name="strFilePath">文件地址</param> /// <returns>执行结果</returns> public bool GetRunCmdDeleteFile(string strFilePath) { try { // 实例化一个进程类 System.Diagnostics.Process MyProcess = new System.Diagnostics.Process(); // 使用命令程序 MyProcess.StartInfo.FileName = "CMD"; // 标准输入 MyProcess.StartInfo.RedirectStandardOutput = true; // 标准输出 MyProcess.StartInfo.RedirectStandardInput = true; // 将cmd的标准输入和输出全部重定向到.NET的程序里,此处必须为false否则引发异常 MyProcess.StartInfo.UseShellExecute = false; // 不显示命令行窗口界面 MyProcess.StartInfo.CreateNoWindow = false; // 启动进程 MyProcess.Start(); // 执行命令 MyProcess.StandardInput.WriteLine(@"DEL " + strFilePath.Trim().ToString()); MyProcess.StandardInput.WriteLine("EXIT"); // 等待执行完成 MyProcess.WaitForExit(); // 关闭进程 MyProcess.Close(); // 返回成功 return true; } catch (System.Exception Exp) // 异常处理 { // 异常信息 System.Diagnostics.Debug.Write(Exp.Message.ToString()); // 返回失败 return false; } finally { } }#endregion
----------------------------------------------------
我有几张阿里云幸运券分享给你,用券购买或者升级阿里云相应产品会有特惠惊喜哦!把想要买的产品的幸运券都领走吧!快下手,马上就要抢光了。
https://promotion.aliyun.com/ntms/act/ambassador/sharetouser.html?userCode=6evata1e&utm_source=6evata1e
点击查看全文
#region 使用CMD命令删除文件函数 /// <summary> /// 使用CMD命令删除文件函数 /// </summary> /// <param name="strFilePath">文件地址</param> /// <returns>执行结果</returns> public bool GetRunCmdDeleteFile(string strFilePath) { try { // 实例化一个进程类 System.Diagnostics.Process MyProcess = new System.Diagnostics.Process(); // 使用命令程序 MyProcess.StartInfo.FileName = "CMD"; // 标准输入 MyProcess.StartInfo.RedirectStandardOutput = true; // 标准输出 MyProcess.StartInfo.RedirectStandardInput = true; // 将cmd的标准输入和输出全部重定向到.NET的程序里,此处必须为false否则引发异常 MyProcess.StartInfo.UseShellExecute = false; // 不显示命令行窗口界面 MyProcess.StartInfo.CreateNoWindow = false; // 启动进程 MyProcess.Start(); // 执行命令 MyProcess.StandardInput.WriteLine(@"DEL " + strFilePath.Trim().ToString()); MyProcess.StandardInput.WriteLine("EXIT"); // 等待执行完成 MyProcess.WaitForExit(); // 关闭进程 MyProcess.Close(); // 返回成功 return true; } catch (System.Exception Exp) // 异常处理 { // 异常信息 System.Diagnostics.Debug.Write(Exp.Message.ToString()); // 返回失败 return false; } finally { } }#endregion
----------------------------------------------------
我有几张阿里云幸运券分享给你,用券购买或者升级阿里云相应产品会有特惠惊喜哦!把想要买的产品的幸运券都领走吧!快下手,马上就要抢光了。
https://promotion.aliyun.com/ntms/act/ambassador/sharetouser.html?userCode=6evata1e&utm_source=6evata1e
阅读全文
0 0
- [C#]使用CMD命令删除文件函数
- cmd del命令 文件删除
- 使用cmd命令删除文件夹下所有文件
- Win10中使用CMD命令遍历文件夹删除重复文件
- bat 文件 复制 删除命令cmd
- 使用CMD命令编译C源文件
- 使用cmd命令制作jar文件
- cmd 命令操纵文件管理器、创建(删除)多级文件夹
- 字符操作、文件操作和CMD命令的使用——c/c++编
- 【C语言小程序】调用CMD命令使用文件资源管理器打开FTP
- cmd删除文件
- c#---运行cmd命令
- cmd文件相关命令
- Widows CMD 命令删除服务
- CMD 新建和删除命令
- 使用DeleteFile函数删除文件
- C语言使用cmd命令并获取输出方法
- C语言使用cmd命令并获取输出方法
- ubuntu16.04--需要运行"apt-get -f install"来纠正下列错误
- 关于Android中Dialog位置的设置
- Ubuntu:Unable to locate package(无法定位安装包)
- 如何操作图像的像素--Mat和vector
- 数据库中间件收集
- [C#]使用CMD命令删除文件函数
- css常用属性
- localhost,127.0.0.1 和 本机IP 三者的区别
- FPGA模块设计“瀑布模型”
- 提示确认框的简单使用
- 自定义RecyclerView之LinearLayoutManager垂直布局
- ESP8266作为TCPServer与其他设备建立一个tcp网络进行局域网通讯
- 平行四边形、梯形导航条
- jmeter安装插件的方法