Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 172305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:08:32+00:00 2026-05-11T13:08:32+00:00

I have the following function that loops through a directory and checks for a

  • 0

I have the following function that loops through a directory and checks for a specified folder and file:

Private Function VerifyPath(ByVal root As String, ByVal folder As String, _                              ByVal file As String) As Boolean      Dim folders As New List(Of String), files As New List(Of String)     Dim oDir As New IO.DirectoryInfo(root)      For Each dir As IO.DirectoryInfo In oDir.GetDirectories         folders.Add(dir.Name.ToLower)     Next     If folders.Contains(folder) Then         For Each item As IO.FileInfo In oDir.GetFiles             files.Add(item.Name.ToLower)         Next         If files.Contains(file) Then             Return True         End If     End If     Return False End Function 

The reason I did this method is so I could make sure that the items in each list and the passed file/folder were all lower case, otherwise I would have done something like this:

If oDir.GetDirectories.Contains( _         New IO.DirectoryInfo(String.Format('{0}\{1}', root, folder))) Then     If oDir.GetFiles.Contains( _             New IO.FileInfo(String.Format('{0}\{1}', root, file))) Then         Return True     End If End If Return False 

My colleague mentioned something to me earlier about being able to ignore case by using a comparer. The .Contains extension can have a comparer argument along with the value. I did some searching on google and MSDN, and came up with the following comparer:

Public Class dirCompare     Implements IEqualityComparer(Of IO.DirectoryInfo)      Dim theCompare As CaseInsensitiveComparer      Sub New()         theCompare = CaseInsensitiveComparer.DefaultInvariant     End Sub      Sub New(ByVal culture As CultureInfo)         theCompare = New CaseInsensitiveComparer(culture)     End Sub      Public Function Equals1(ByVal x As System.IO.DirectoryInfo, ByVal y As System.IO.DirectoryInfo) As Boolean Implements System.Collections.Generic.IEqualityComparer(Of System.IO.DirectoryInfo).Equals         If theCompare.Compare(x.name, y.name) = 0 Then             Return True         Else             Return False         End If     End Function      Public Function GetHashCode1(ByVal obj As System.IO.DirectoryInfo) As Integer Implements System.Collections.Generic.IEqualityComparer(Of System.IO.DirectoryInfo).GetHashCode         Return obj.ToString.ToLower.GetHashCode     End Function End Class 

When it gets to the theCompare(x.name, y.name) = 0 line, it errors out and this is the error message:

At least one object must implement IComparable.

Anyone know what this error means and how to go about correcting it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T13:08:33+00:00Added an answer on May 11, 2026 at 1:08 pm

    Well you could implement a comparer, but that would be the hard way in this case. You have a couple other options available instead.

    The first is that there is already a case-insensitive comparer you can use. There are a couple actually. Look in your intellisense prompts under System.StringComparer.

    The second is that strings already have a built-in way to specify a case-insensitive compare:

    Dim s As String = 'a' Dim t As String = 'A' If s.Equals(t, StringComparison.InvariantCultureIgnoreCase) Then    ''//... End If 

    And a third is that any searchPattern passed to Directory.GetFiles() or Directory.GetDirectories() is passed directly to the operating system, and Windows is only case-aware for file names, not case-sensitive. So you can pass your folder and file as a search pattern and do your lookup that way.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 180k
  • Answers 180k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The solution to this problem was that I was not… May 12, 2026 at 4:06 pm
  • Editorial Team
    Editorial Team added an answer It is the equation of a (hyper)plane using a point… May 12, 2026 at 4:06 pm
  • Editorial Team
    Editorial Team added an answer from the vim help :help word *word* A word consists… May 12, 2026 at 4:06 pm

Related Questions

I have some Haskell code that does work correctly on an infinite list, but
I have the following situation: I have a certain function that runs a loop
I have a tab-delimited text file that I am parsing. Its first column contains
I have a WCF service with a security class for getting some of the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.