Reputation: 99
I am trying to get all the sub-directories under C:\Program Files (x86)\Java\ Which should be jre1.8.0_25 for my computer, could have more if different versions are installed that's good, i want that. But all i ever get is java from this code
Directory.GetDirectories("C:\Program Files (x86)\Java\", SearchOption.AllDirectories))
or
New System.IO.DirectoryInfo("C:\Program Files (x86)\Java").Name)
Where am i going wrong?
The goal is the insert that output from the above code into a database. I used to read it from the registry but Java8 doesn't work for my old code anymore.
Upvotes: 0
Views: 1097
Reputation: 38865
First, this overload does not exist: GetDirectories(string, options)
There is:
GetDirectories(path as string)
GetDirectories(path as string, pattern as string)
GetDirectories(path as string, pattern as string, options As SearchOptions)
None of those match the way you are using it.
Second, you should not assume the name of system folders such as "C:\Program Files (x86)" - a German or French computer will not have such a folder.
This returns 75 folders on my machine:
' get program files
Dim fpath As String = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86)
' append java
fpath = Path.Combine(fpath, "Java")
' fetch
Dim folders = Directory.GetDirectories(fpath, "*", SearchOption.AllDirectories)
Upvotes: 1
Reputation: 5545
Try this instead:
? = New System.IO.DirectoryInfo("C:\Program Files (x86)\Java").GetDirectories(SearchOption.AllDirectories)
Upvotes: 0