What I am trying to do is search through a folder's subdirectories and any folders that have /Year/Month/ I want to pull the files from that folder.
The folder paths are typically as follows
BaseFilePath\Group1\SubGroup1\Year\Month BaseFilePath\Group1\Year\Month
The goal is to move those files into another folder and while I have tried iterating through the whole directory it just seems to take too long, and I was wondering if there was a quicker or easier solution.
The code I was using to do this is as follows
Dim topLevelFolder As New DirectoryInfo("\\BaseFilePath\")
Using outputFile As New StreamWriter("C:\output_file.txt")
For Each currentFile In topLevelFolder.EnumerateFiles("*.*", SearchOption.AllDirectories)
Try
If currentFile.Directory.Name = "June" AndAlso currentFile.Directory.Parent.Name = "2014" AndAlso Left(currentFile.Name, 5) <> "SENT_" Then
outputFile.WriteLine(currentFile.Directory.Parent.Parent.Name & "/" & currentFile.Directory.Parent.Name & "/" & currentFile.Directory.Name & "/" & currentFile.Name)
End If
Catch
End Try
Next
End Using
This portion alone is already taking close to 30 seconds, and I'd imagine moving the files to another folder is going to take some time too, but if I can speed up the finding of the files the whole process would go smoother.
I saw that you can use wildcards in the searchPattern, but when I tried I got illegal characters in path or Second path fragment must not be a drive or UNC name. I know individual wildcards are useable ie (BaseFilePath\partialFolderName*) but doesn't seem to help when it extends to multiple directories being wildcarded.
Ideally what I'm looking to do is search BaseFilePath*2014\June* and only pull files from those folders.
Any help or suggestions would be greatly appreciated