C#正则表达式校验,判断文件是否存在,复制保存
来源:互联网 发布:嵌入式网络编程 编辑:程序博客网 时间:2024/05/22 07:29
System.Text.RegularExpressions.Regex rgx = new System.Text.RegularExpressions.Regex(@"\d{10}.");
string sNewFileName = rgx.Replace(str_文件路径,".");
if (System.IO.File.Exists(System.IO.Path.GetFullPath(sNewFileName)))
{
//MessageBox.Show("当前路径已经存在,需要先进行删除!");
System.IO.File.Delete(System.IO.Path.GetFullPath(sNewFileName));
}
try{
System.IO.FileInfo fi = new System.IO.FileInfo(str_文件路径);
fi.MoveTo(System.IO.Path.Combine(str_文件路径.Substring(0,str_文件路径.LastIndexOf('\\')-1),sNewFileName));
return sNewFileName;
}
catch(System.Exception exp){
//MessageBox.Show(exp.ToString());
return str_文件路径;
}
string sNewFileName = rgx.Replace(str_文件路径,".");
if (System.IO.File.Exists(System.IO.Path.GetFullPath(sNewFileName)))
{
//MessageBox.Show("当前路径已经存在,需要先进行删除!");
System.IO.File.Delete(System.IO.Path.GetFullPath(sNewFileName));
}
try{
System.IO.FileInfo fi = new System.IO.FileInfo(str_文件路径);
fi.MoveTo(System.IO.Path.Combine(str_文件路径.Substring(0,str_文件路径.LastIndexOf('\\')-1),sNewFileName));
return sNewFileName;
}
catch(System.Exception exp){
//MessageBox.Show(exp.ToString());
return str_文件路径;
}
0 0
- C#正则表达式校验,判断文件是否存在,复制保存
- C# 判断 文件路径/文件 是否存在
- C#怎样判断文件是否存在和文件夹是否存在
- C#判断文件及文件夹是否存在
- C#判断文件是否存在方法
- C#判断远程文件是否存在
- C#判断某个文件是否存在
- c# 判断远程文件是否存在
- C# C++ 判断文件 文件夹是否存在
- C# 判断远程文件是否存在
- C# 检查网络是否连通,判断远程文件是否存在
- 判断文件是否存在
- 判断文件是否存在
- 判断文件是否存在
- 判断文件是否存在
- 判断文件是否存在
- 判断文件是否存在
- 判断文件是否存在
- 51Nod-1682-中位数计数
- 文字滚动形成
- POJ 3077-Rounders
- c语言学习---基本命令
- 初学Redis(4)——简单实现Redis缓存中的排序功能(转载)
- C#正则表达式校验,判断文件是否存在,复制保存
- html5-css简介和属性:border、background、font
- 框架-框架的侵入性-解释
- 强烈推荐!教你测试手机网页的五大方法
- ubuntu 15.04 系统中如何启用、禁用客人会话
- 数据结构实验之二叉树的建立与遍历
- 111
- App系列------如何把文件放到assets目录下
- [DP]Composite设计模式