0

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.

1
Contributor
2
Replies
17
Views
4 Years
Discussion Span
Last Post by Tinnin
0

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.

1

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.

Votes + Comments
Love to see when some one figures it out on their own!
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.