I understand how to rename a file in VB.NET , as I use in the code at the end of my post. However, I was wondering if it is possible to rename a file and if the file exists, then rename it and add +1 to the file name?
So, if I run the code.
'Run it for the first time
My.Computer.FileSystem.RenameFile("c:\test\test.txt", "c:\test\NewName.txt")
'Run it again, but it should add +1 because the file already exists, so it should be "c: \ test \ NewName1.txt"
My.Computer.FileSystem.RenameFile("c:\test\test.txt", "c:\test\NewName.txt")
Update
I decided, but did not rename +1, it would be better to just stamp it, so for those who are struggling, like me:
My.Computer.FileSystem.RenameFile("c:\test\test.txt", "Test" & Format(Date.Now, "ddMMyy") & ".txt")
source
share