thebatfink
Well-known member
- Joined
- Mar 29, 2012
- Messages
- 47
- Programming Experience
- Beginner
Ok, so here's what I am trying to achieve -
1) Get a root folder using a browse prompt
2) Recursively scan the folder and find all excel files ("*.xl*")
3) Count the number of files so I can update my forms text box to display number files found to user
4) Create a listbox containing the filenames to display to the user
5) Put the filenames into an array for processing later in the application
I'm achieving that using the code below. What I want to do now is change requirement number 2 above to.. Include filenames where filename like "*.xl*" = TRUE AND filename like "*.xlt*" = FALSE.
I don't think this is possible with the GetFiles method? But is there a logical workaround to achieve this that any one can think of as its frying my brain!
Thanks for any help!
1) Get a root folder using a browse prompt
2) Recursively scan the folder and find all excel files ("*.xl*")
3) Count the number of files so I can update my forms text box to display number files found to user
4) Create a listbox containing the filenames to display to the user
5) Put the filenames into an array for processing later in the application
I'm achieving that using the code below. What I want to do now is change requirement number 2 above to.. Include filenames where filename like "*.xl*" = TRUE AND filename like "*.xlt*" = FALSE.
I don't think this is possible with the GetFiles method? But is there a logical workaround to achieve this that any one can think of as its frying my brain!
VB.NET:
'Get root folder
Dim SelectedFolderName as string = FolderBrowserDialog1.SelectedPath
'Count number of files which match wildcard *.xl*
Dim counter = My.Computer.FileSystem.GetFiles(SelectedFolderName, FileIO.SearchOption.SearchAllSubDirectories, "*.xl*")
'Display number of found files on form
Form1.TextBox1.Text = CStr(counter.Count)
Dim ArrayPosition As Integer = 0
'Set array size to total number of files found
ReDim SelectedFileList(CStr(counter.Count) - 1)
For Each FoundFile As String In My.Computer.FileSystem.GetFiles(SelectedFolderName, FileIO.SearchOption.SearchAllSubDirectories, "*.xl*")
'For each file add filename/path to listbox for display to user and add the filename/path to the array for use later
Form3.ListBox1.Items.Add(FoundFile)
SelectedFileList(ArrayPosition) = FoundFile
ArrayPosition = ArrayPosition + 1
Next
Thanks for any help!