如果指定的文件名已经存在的方式来获得唯一的文件名(.NET) [英] Way to get unique filename if specified filename already exists (.NET)

查看:135
本文介绍了如果指定的文件名已经存在的方式来获得唯一的文件名(.NET)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个内置的.NET功能,如果一个文件名已经存在,获得唯一的文件名?所以,如果我尽力挽救 MYDOC.DOC 键,它已经存在,该文件将保存名为 MyDoc(1)的.doc ,以同样的方式在浏览器下载适用于例如。

Is there a built in .NET function to get a unique filename if a filename already exists? So if I try and save MyDoc.doc and it already exists, the file will save with name MyDoc(1).doc, the same way a browser download works for example.

如果没有,什么是实现这一结果的最有效方法是什么?

If not, what is the most efficient way to achieve this result?

我现在用的是 File.Move 功能目前BTW。

I am using the File.Move function at the moment btw.

推荐答案

核对正则表达式的名字* \(\ D + \),如果它不匹配,加入(1),如果匹配增加括号内的数字。

check the name against Regex *.\(\d+\), if it doesn't match, add (1), if it matches increment the number in brackets.

这篇关于如果指定的文件名已经存在的方式来获得唯一的文件名(.NET)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆