[C#]使用CMD命令删除文件函数

点击查看全文




#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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值