[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


原创粉丝点击