Hi all,
I have some basic code to create an array of filenames in a folder. All good.
I remove the timestamps and extensions from the files, which leaves small groups of files with the exact same name.
eg:
Dave
Dave
Dave
Fred
Fred
Fred
John
John
John
etc
These are all added to the array.
However I need each name to appear only once in the array.
At what point do I check whether the name already exists in the array?
Can it be done before adding the name to the array?
Or does it have to be done after it has been preserved?
I have some basic code to create an array of filenames in a folder. All good.
I remove the timestamps and extensions from the files, which leaves small groups of files with the exact same name.
eg:
Dave
Dave
Dave
Fred
Fred
Fred
John
John
John
etc
These are all added to the array.
However I need each name to appear only once in the array.
At what point do I check whether the name already exists in the array?
Can it be done before adding the name to the array?
Or does it have to be done after it has been preserved?
Code:
Sub Create_Array()
Dim MyFile As String
Dim Counter As Long
Dim DirectoryListArray() As String
ReDim DirectoryListArray(50)
MyFile = Dir$("C:\junk\357536080015052\*.res")
Do While MyFile <> ""
ResFileName = (Left(MyFile, Len(MyFile) - 22)) ' This means there are several files with the same name once the timestamps are removed.
DirectoryListArray(Counter) = ResFileName
MyFile = Dir$
Counter = Counter + 1
Loop
ReDim Preserve DirectoryListArray(Counter - 1)
'Print the array content to check
For Counter = 0 To UBound(DirectoryListArray)
Debug.Print DirectoryListArray(Counter)
Next Counter
End Sub