C#删除指定路径文件、修改指定文件名、转移指定文件到指定路径

string virtualPath = "~/Content/reports/Product";
string oldFileName = this.Server.MapPath(string.Format(virtualPath + "/{0}", oldfileName));    //完整文件路径

oldFileName :       D:\\XX\\Content\\reports\\Product\\AA.doc
string newFileName= this.Server.MapPath(string.Format(virtualPath + "/{0}{1}", proInfo.F_EnCode, FileEextension));  newFileName:       D:\\XX\\Content\\reports\\Product\\XX.doc

//FileEextension 后缀名
                
                if (System.IO.File.Exists(oldFileName))
                {
                    if (System.IO.File.Exists(newFileName))
                    {
                        string path = Path.GetDirectoryName(newFileName);
                        DirectoryInfo Folder = new DirectoryInfo(path);
                        IEnumerable<FileInfo> file = Folder.GetFiles().Where(t => t.FullName == newFileName);
                        foreach (var item in file)
                        {
                            item.Delete();        //删除文件名为newFileName的文件

                            //item.MoveTo(Path.Combine(destFolder, newFileName));    //destFolder目的文件夹,

//不包含文件   newFileName新的文件名                
                        }
                    }
                    System.IO.File.Move(oldFileName, newFileName);         //修改文件名为newFileName   oldFileName是旧名字

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值