更新时间:2022-10-15 10:19:34
有一个功能可能有用。
file.exists(strpath& \ new.pdf)
http://msdn.microsoft.com/en-us /library/system.io.file.aspx [ ^ ]
所以你可以使用它类似于
if file.exists(strpath& \ new.pdf)
' 您在此处更改文件名的代码
结束 如果
如何生成fileName
Dim 路径为跨度> 字符串跨度> = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
Dim fileName 作为 字符串 = new.pdf
Dim count 正如 整数 = 1
while System.IO.File.Exists(System.IO.Path.Combine(path,fileName))
count =(count + 1 )
fileName =( new _ _
+(count.ToString + 。pdf))
结束
然后你可以简单地使用:Dim strPath 为跨度> 字符串跨度> = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
.WritePDF(strPath的+文件名)
Hi all
i wrote the below code to create a pdf named "new.pdf" at desktop
Dim strPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
.WritePDF(strPath + "\new.pdf")
Now i want to check if the file "new.pdf" is already present then it should create file name like "new_1.pdf","new_2.pdf" and so on else it will create "new.pdf" and the next files
Please tell me how to do this
there is a function that may be of some use.file.exists( strpath & "\new.pdf" )
http://msdn.microsoft.com/en-us/library/system.io.file.aspx[^]
so you could use it similar toif file.exists( strpath & "\new.pdf" ) then 'Your code to change filename here end if
How about this, for generating yourfileName
Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) Dim fileName As String = "new.pdf" Dim count As Integer = 1 While System.IO.File.Exists(System.IO.Path.Combine(path, fileName)) count = (count + 1) fileName = ("new_" _ + (count.ToString + ".pdf")) End While
Then you can simple use:Dim strPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) .WritePDF(strPath + fileName)