can anyone help me with this? im having trouble with renaming a file.. the last 2 digit of DT102T01 up to DT102T15 will count according to the number of files inside the Data_PRN folder. please help! any suggestion will be appreciated.. tnx

'===== make directory & rename file . prn to .txt =======

            Dim PRNname As String
            Dim TXTname As String
            Dim MakeDirectory As String = "C:\CHRONOLOG"
            If System.IO.File.Exists(MakeDirectory) = True Then
                MsgBox("Folder already exist", vbInformation, )
            End If
                Dim md As System.IO.DirectoryInfo = CreateDirectory(MakeDirectory)
                MsgBox("File/Folder created")
            Console.WriteLine("File/Folder created at {0}", System.IO.File.GetCreationTime(MakeDirectory))

            mdcount = 1
            directoryCount = System.IO.Directory.GetFiles("C:\Data_PRN\", "*.*", IO.SearchOption.AllDirectories).Length()
            Dim CopyFile As String
            Dim PasteFile As String
            CopyFile = "C:\Data_PRN"
            PasteFile = "C:\CHRONOLOG\"
            If Not My.Computer.FileSystem.FileExists(CopyFile) = True Then
                My.Computer.FileSystem.CopyDirectory(CopyFile, PasteFile)
                MsgBox("Files copied")
                MsgBox("Already exists")
            End If
            'Dim Sfile As String = "C:\DT102T*" & mdcount & ".prn"
            ' Dim Sfile As String = Dir(PathName:="C:\Data_PRN\DT102T*" & mdcount & ".prn", Attributes:=FileAttribute.Normal)

 Do While mdcount <= directoryCount
                PRNname = "C:\Data_PRN\DT102T*" & mdcount & ".prn"
                [B][COLOR="Red"]TXTname = "C:\CHRONOLOG\DT102T*" & mdcount & ".txt"[/COLOR][/B]
                Rename(PRNname, TXTname)
                mdcount += 1

Edited 3 Years Ago by Nick Evan: Fixed formatting

the problem is the TXTname.. the 0 in \DT102T01. i want the 0 to be included in DT102T because 1 is in the loop mdcount.

the program is running but the data didnt change its name from .prn to .txt because the DT102T cannot find 0..

This article has been dead for over six months. Start a new discussion instead.