Home > Enterprise >  How can I get the correct text case of a user inputted file or directory in Delphi?
How can I get the correct text case of a user inputted file or directory in Delphi?

Time:10-06

In my (Windows) program a user can input text and that text can be a file or a directory.

Now I want to fix the text case so that the input text match the file system case. For example if a user inputs:

C:\PROGRAM FILES\FOO\BAR

and the directory exists with this text case:

C:\Program Files\Foo\Bar

I want to return it with the later (correct) text case.

How would I do that in Delphi? I tried using FindFirst and FindNext, but I don't have the full path in the TSearchRec (of course I could split the string and do multiple FindFirst for each level, but there must be a better way).

I use Delphi 10.4 if it changes something.

CodePudding user response:

Open a handle to the file/directory using CreateFile(), and then you can use either:

  • Related