Hi all,

I'm trying to change the file extensions of some excel files to csv and add the file names to a list box. The box is coming up blank however.

My code is as follows:

Private Sub Project_Load(sender As Object, e As EventArgs) Handles Me.Load

        Dim importsFileList As New ArrayList
        Dim sFile As String
        Dim extension As String
        Dim newExtension As String

        sFile = Dir$("C:\Users\filepath" & "\*.*", vbDirectory)
        Do Until sFile = vbNullString
            If sFile <> "." Then ' relative path meaning this directory
                If sFile <> ".." Then ' relative path meaning parent directory 
                    extension = IO.Path.GetExtension(sFile)
                    If extension = ".xls" Or extension = ".xlsx" Then
                        Dim fInfo As IO.FileInfo = New IO.FileInfo(sFile)
                        newExtension = IO.Path.ChangeExtension(sFile, ".csv")
                        fInfo.MoveTo(newExtension)
                    End If
                End If
            End If
            sFile = Dir$()
        Loop

        sFile = Dir$("C:\Users\filepath" & "\*.*", vbDirectory)
        Do Until sFile = vbNullString
            If sFile <> "." Then ' relative path meaning this directory
                If sFile <> ".." Then ' relative path meaning parent directory 
                    extension = IO.Path.GetExtension(sFile)
                    If extension = ".csv" Then
                        importsFileList.Add(sFile)
                    End If
                End If
            End If
            sFile = Dir$()
        Loop

        For Each importedFile In importsFileList
            ImportFiles.Items.Add(importedFile)
        Next

Where am I going wrong?

Thanks in advance for any suggestions offered.

I've now managed to change the file name using

My.Computer.FileSystem.RenameFile(source, destination)

but I still can't get the files to show up in the list.

Problem solved. It appeared that a file I was checking in the loop was already open elsewhere in the background and the loop was exiting at that point and ending the program.

Live and learn.

commented: Love to see when some one figures it out on their own! +8
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.