Ignore case sensitive

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Evolution445
    New Member
    • Jul 2007
    • 63

    Ignore case sensitive

    Hi,

    I currently have this code:

    Code:
    If IO.File.Exists(txt_Path.Text & "\names.txt") Then
    SaveSetting("Search", "Main", "Found", "1")
    MessageBox.Show("Found names.txt")
    btn_Edit.Enabled = True
    Else
    SaveSetting("Search", "Main", "Found", "0")
    MessageBox.Show("Could not find names.txt")
    End If
    But my problem is that "names.txt" can be: Names.txt, NAMES.TXT, NaMeS.TxT, anything.

    How do I make sure that it will just find "names.txt" , ignoring difference between capitals or lower case letters ?


    Thanks in advance,
    Evolution445
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Well you'd have to move to a non-windows system for starters.
    Windows doesn't differentiate on case at the filesystem level.
    Try and make a file called mytxt.txt and Mytxt.txt in the same directory, it won't let you.
    Last edited by balabaster; Jan 23 '09, 10:07 PM. Reason: correct spelling

    Comment

    • balabaster
      Recognized Expert Contributor
      • Mar 2007
      • 798

      #3
      Am I understanding that you correctly?

      The file name as it is stored on the file system is "names.txt" in all lower case, but the user may enter the search file name as "Names.txt" and vice versa?

      It may be stored as "Names.txt" and the user enters "names.txt" and it should still find the file?

      System.IO.File. Exists() is not case sensitive. As such, it should return true regardless of the case of the file name provided and the file name on the file system. If for instance, the file was called "names.txt" on the file system and you provided "NaMeS.tXt" as the input parameter to File.Exists(), it would still return true.

      Comment

      • Evolution445
        New Member
        • Jul 2007
        • 63

        #4
        Thanks for your quick replies.

        I feel stupid now. I forgot to add "= True". I just had:
        If IO.File.Exists( ) Then

        It now is:
        If IO.File.Exists( ) = True Then

        And now is working as it should.


        Thanks again.
        Evolution445

        Comment

        • Curtis Rutland
          Recognized Expert Specialist
          • Apr 2008
          • 3264

          #5
          That shouldn't matter at all. A boolean value is a boolean value. True = True evaluates to True.

          Comment

          • Evolution445
            New Member
            • Jul 2007
            • 63

            #6
            I put names.txt in my directory, it got picked up. Then renamed it to NaMeS.TxT, and it told me it wasnt there. Then added "= True", and "Import System.IO" at the top, and it found the file straight away. Maybe in rush I mis-spelled the file, or I made an error somewhere else.

            Comment

            Working...