Reputation: 13
I'm working on a program to parse a file name based on a drag drop, and process and remove a list of words that may be found in the file. I had the program working, but in a not so elegant manner, as well as a manner that would introduce issues later on in the program.
I'm trying create a list of a custom class or structure.
Here's what I have:
Public Class moviePath
Public currentPath As String
Public currentNameExt As String
Public currentName As String
Public currentExt As String
Public correctedName As String
Public correctYear As String
End Class
The issue is then when I attempt to create a usable variable based on this:
Dim workingList as New List(Of moviePath)
I'm left with no good way to correctly add data to the list using subs such as this:
Sub scanParent(ByVal sDir As String)
Dim f As String
Dim i As Integer = 0
Try
For Each f In Directory.GetFiles(sDir)
workingList(i).currentName = (Path.GetFileNameWithoutExtension(f))
workingList(i).currentNameExt = (Path.GetFileName(f))
workingList(i).currentPath = (Path.GetFullPath(f))
i += 1
Next
Catch excpt As System.Exception
MessageBox.Show("It didn't work " & excpt.ToString)
End Try
End Sub
Hopefully those tidbits make sense. scanParent
sub is called passing the path to a folder as the argument (ie C\somefolder) and I intend to populate an array of sorts with information about files and folders. My reasoning is that I would like to be able to remove words from movie titles, in order use a opensource library (not sure if correct language) that parses IMDB to pull in movie info.
The main thing that I need is for each item in the class moviePath to be addressable and tied to each other item at that position in the list.
EDIT: ie. moviePath(0).currentPath
would be in reference to the same file moviePath(0).currentName
Upvotes: 0
Views: 99
Reputation: 39122
I agree with Plutonix. In addition to the fix by Bradley, also pass the FileName to your movePath class like this:
Public Class moviePath
Public Sub New(ByVal FullFilePath As String)
Me.currentPath = FullFilePath
Me.currentName = Path.GetFileNameWithoutExtension(FullFilePath)
Me.currentNameExt = Path.GetFileName(FullFilePath)
End Sub
Public currentPath As String
Public currentNameExt As String
Public currentName As String
Public currentExt As String
Public correctedName As String
Public correctYear As String
End Class
Now your loop becomes simply:
For Each f In Directory.GetFiles(sDir)
workingList.add(New moviePath(f))
Next
Upvotes: 0
Reputation: 2639
You should be using the List(T).Add method for this.
Sub scanParent(ByVal sDir As String)
Dim f As String
Try
For Each f In Directory.GetFiles(sDir)
Dim newPath As New moviePath()
newPath.currentName = (Path.GetFileNameWithoutExtension(f))
newPath.currentNameExt = (Path.GetFileName(f))
newPath.currentPath = (Path.GetFullPath(f))
workingList.Add(newPath)
Next
Catch excpt As System.Exception
MessageBox.Show("It didn't work " & excpt.ToString)
End Try
End Sub
Upvotes: 0
Reputation: 16991
For Each f In Directory.GetFiles(sDir)
dim info as new moviePath
info.currentName = (Path.GetFileNameWithoutExtension(f))
info.currentNameExt = (Path.GetFileName(f))
info.currentPath = (Path.GetFullPath(f))
workingList.add(info)
Next
Upvotes: 1