I verified all the directory paths exist so I am completely at a loss here.
For Each i As Project.ImageryCaptureTask.FileProperties In t.FileCollection
Dim NewFilename As New FileInfo(Path.Combine(Root.FullName, i.LVItem.Text))
If NewFilename.Exists Then
' ...Things get done
Else
Try
i.FI.MoveTo(NewFilename.FullName) ' <- Error thrown here (obviously)
Catch IOEx As IOException
MsgBox(IOEx.Message & vbCr & vbCr & "Error renaming to " & NewFilename.FullName, vbOKOnly, IOEx.Source)
Catch Ex As Exception
MsgBox(Ex.Message & vbCr & vbCr & "Error renaming to " & NewFilename.FullName, vbOKOnly, IOEx.Source)
End Try
End If
Next
Edit
Sorry, I was trying to keep the question short and quick, but I failed to provide the key information about Root.FullName
. Here is the snippet to show that.
' P.MainFolder.FullName is the DirectoryInfo instantiated from the FolderBrowserDialog
If Directory.Exists(P.MainFolder.FullName) Then
For Each t As Project.ImageryCaptureTask In P.TaskCollection
Dim SubFolder3DMapping As New DirectoryInfo(Path.Combine(P.MainFolder.FullName, (Val(t.TaskCreationDate) + t.OffsetDate).ToString & "_" & P.ProjectNumber & "_" & P.ProjectName & "_" & Project.ImageryCaptureTask.CapturingMethods.Aerial3DMapping.ToString.Insert(6, "_")))
Dim SubFolderPhotos As New DirectoryInfo(Path.Combine(P.MainFolder.FullName, (Val(t.TaskCreationDate) + t.OffsetDate).ToString & "_" & P.ProjectNumber & "_" & P.ProjectName & "_" & Project.ImageryCaptureTask.CapturingMethods.AerialPhotos.ToString.Insert(6, "_")))
Dim SubFolderVideos As New DirectoryInfo(Path.Combine(P.MainFolder.FullName, (Val(t.TaskCreationDate) + t.OffsetDate).ToString & "_" & P.ProjectNumber & "_" & P.ProjectName & "_" & Project.ImageryCaptureTask.CapturingMethods.AerialVideos.ToString.Insert(6, "_")))
If Not SubFolder3DMapping.Exists Then SubFolder3DMapping.Create()
If Not SubFolderPhotos.Exists Then SubFolderPhotos.Create()
If Not SubFolderVideos.Exists Then SubFolderVideos.Create()
Dim Root As DirectoryInfo = Nothing
Select Case True
Case t.CaptureMethod = Project.ImageryCaptureTask.CapturingMethods.Aerial3DMapping
Root = SubFolder3DMapping
Case t.CaptureMethod = Project.ImageryCaptureTask.CapturingMethods.AerialPhotos
Root = SubFolderPhotos
Case t.CaptureMethod = Project.ImageryCaptureTask.CapturingMethods.AerialVideos
Root = SubFolderVideos
End Select
For Each i As Project.ImageryCaptureTask.FileProperties In t.FileCollection
Dim NewFilename As New FileInfo(Path.Combine(Root.FullName, i.LVItem.Text))
If NewFilename.Exists Then
' This should not happen, but if it does it gets handled here.
Else
Try
i.FI.MoveTo(NewFilename.FullName)
Catch IOEx As IOException
MsgBox(IOEx.Message & vbCr & vbCr & "Error renaming to " & NewFilename.FullName, vbOKOnly, IOEx.Source)
Catch Ex As Exception
MsgBox(Ex.Message)
End Try
End If
Next
Next
End If
Here is a photo showing the results from the last attempt. Of the 33 files, 7 of them failed to be renamed:
The goal here is to rename the image files created during our drone flights. These flights are static, same amount of images at the same GPS locations, so we want to be able to reference any existing flight images so we can extract the filenames. The only dynamic part of the filenames are the first 8 characters (Date: yyyymmDD).