I have a mass of files, all named 1.txt, 2.txt, etc. all the way up to 100.txt in the same directory (let's say C:\Example1) that have come from a website and are either of one of the two following formats:

"blah blah blah, 1234, blahblah" (Always 4 numbers, as it's a year)

or, alternatively:

"blah blah blah, 1234, blah blah"
" , , "

I'd like to convert them to one CSV format, using the commas inside the text files at the moment as the delimiters in the CSV file, with all of the data in the

See if this helps.

'// original .txt Folder with .txt Files.
        Dim myTXT_folder As String = "C:\tempTXT\"
        '// .csv Folder to save Files to.
        Dim myCSV_folder As String = "C:\tempCSV\"
        '// create a temporary TextBox.
        Dim tempTextBox As New TextBox With {.Multiline = True}
        '// loop thru the .txt Files Folder.
        For Each myTXT_File As String In My.Computer.FileSystem.GetFiles _
                                            (myTXT_folder, FileIO.SearchOption.SearchTopLevelOnly, "*.txt")
            '// load .txt File in your temporary TextBox.
            tempTextBox.Text = IO.File.ReadAllText(myTXT_File)
            '// save temporary TextBox text as new .csv File and keep the same File Name.
            IO.File.WriteAllText(myCSV_folder & IO.Path.GetFileNameWithoutExtension(myTXT_File) & ".CSV", tempTextBox.Text)
        Next
        MsgBox("Done.", MsgBoxStyle.Information) '// display confirmation when done.
        tempTextBox.Dispose() '// dispose of the temporary TextBox.

Does this code also load the data from C:\Example1, or will I need extra code to do that?(I don't know how to do this in VB.NET - I can do it in VB 6.0 no problem, but VB.NET is a whole new world to me)

My previously posted code will only "convert" the files from .txt to .csv in a specified folder.

The code loads each .txt file from a folder into a temporary TextBox and saves that loaded text with the same FileName and a new File extension, .csv in this case.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.