I'm trying to write a simple simple program. It should be trivial, but I'm coming across an error I don't quite get. The program is a picture sorter. Nothing special, it just shows all the pictures in a directory one at a time and then lets me choose where to send them. I could do the same thing manually by looking at the pictures and moving them with cut/paste, this is just (supposed to be) faster. The problem is I keep getting an error when I try to move the file with code, telling me the file is being used by another process (which as far as I know it's not).
Any ideas what I'm doing wrong? (Being a large noob here, I know...)
Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim fileList As System.Collections.ObjectModel.ReadOnlyCollection(Of String)
Me.Show()
My.Computer.FileSystem.CurrentDirectory = "D:\BP2\Pictures\"
fileList = My.Computer.FileSystem.GetFiles(My.Computer.FileSystem.CurrentDirectory, FileIO.SearchOption.SearchTopLevelOnly, "*.*")
For Each foundFile As String In fileList
lstFiles.Items.Add(foundFile)
Next
pbShowPic.Image = Image.FromFile(lstFiles.Items(0))
PicIndex = 0
oldfile = ""
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
oldfile = lstFiles.Items(0)
newfile = "D:\Nature\Pictures\Bears" & Mid(lstFiles.Items(0), InStrRev(lstFiles.Items(0), "\"))
lstFiles.Items.RemoveAt(0)
pbShowPic.Image = Image.FromFile(lstFiles.Items(0))
My.Computer.FileSystem.RenameFile(oldfile, newfile)
End Sub
Any ideas what I'm doing wrong? (Being a large noob here, I know...)