I have a huge problem here related to VB.Net coding.
I have a folder named Demo located in my C drive. And I have a project which will create DAT files in this folder. Now my problem is. I have to change the file name if file is exists like this way NOUHINHD.DAT -- NOUHHD01.DAT -- NOUHHD02.DAT -- NOUHHD03.DAT ---- NOUHHD10.DAT
.
That mean if the file NOUHINHD.DAT
exists then I have to rename NOUHINHD.DAT
to NOUHHD01.DAT
and create a new file name called NOUHINHD.DAT
.
Same like if I have file Name called NOUHHD10
then rename it to NOUHHD11
and continuously rename those 10 file with increasing number and always create a new file NOUHINHD.DAT
.
I am using this code
Dim path As String = "C:\DEMO\"
no = 10
For Each filename As String In System.IO.Directory.GetFiles(path)
Dim name As String = (System.IO.Path.GetFileNameWithoutExtension(filename))
Dim number As String = (Mid(name, 7))
If number = "HD" Then
My.Computer.FileSystem.RenameFile(path + name + ".DAT", "NOUHHD01.DAT")
ElseIf number >= 1 Then
'For i As Integer = 0 To 0
' ArrayName(10) = number
'Next
Try
My.Computer.FileSystem.RenameFile(path + name + ".DAT", "NOUHHD0" + (Convert.ToInt32(number) + 1).ToString + ".DAT")
Catch ex As Exception
ErrorMessage(ex.ToString)
End Try
Else
Return Nothing
End If
Next
If Not File.Exists(path + "NOUHINHD.DAT") Then
IBR_SJK_C050.CsvUtil.WriteCSVFile(dt, path + "NOUHINHD.DAT")
End If
for creating those file but it create me like this format DEMO.DAT -- DEMO02.DAT -- DEMO04.DAT -- DEMO06.DAT
. It is increasing by two times but it should increase just 1 times.