在我的 vb.net winform 应用程序中,我正在移动文件(例如:sample.xls 从一个文件夹到另一个文件夹。如果文件已存在同名,则应增加新文件名(例如:sample(1).xls ). 我怎样才能做到这一点?
最佳答案
嗨,这是一个非常“程序化”的答案:
Dim counter As Integer = 0
Dim newFileName As String = orginialFileName
While File.Exists(newFileName)
counter = counter + 1
newFileName = String.Format("{0}({1}", orginialFileName, counter.ToString())
End While
您将需要 System.IO 的导入语句
关于.net - 如果文件已存在,如何增加文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6264098/