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:
GetFileInformationByHandleEx()
, setting theFileInformationClass
parameter toFileNameInfo
NtQueryInformationFile()
, setting theFileInformationClass
parameter toFileNameInformation