In a case-insensitive file system like Windows, is there a routine for returning a filename in its original case, eg if a file is saved as 'aBcDe' and the user entered 'abcde' which locates the file, is there a routine that can check the file system and and return 'aBcDe' as the original spelling?All file related routines for FPC/Lazarus preserve filename case as it is a filesystem/OS related matter.
In a case-insensitive file system like Windows, is there a routine for returning a filename in its original case, eg if a file is saved as 'aBcDe' and the user entered 'abcde' which locates the file, is there a routine that can check the file system and and return 'aBcDe' as the original spelling?Not sure if there is a ready made function.
In a case-insensitive file system like Windows, is there a routine for returning a filename in its original case, eg if a file is saved as 'aBcDe' and the user entered 'abcde' which locates the file, is there a routine that can check the file system and and return 'aBcDe' as the original spelling?Not sure if there is a ready made function.
But you could use something like this:
function GiveCorrectCaseFileName(Filename: String): String; var Sr: TSearchRec; begin Result := ''; if FindFirst(Filename, faAnyFile and faDirectory, Sr) = 0 then Result := ExtractFilePath(Filename) + Sr.Name; FindClose(Sr); end; procedure TForm1.Button1Click(Sender: TObject); begin Showmessage(GiveCorrectCaseFileName('c:\temp\TeSt.tXt')); end;
(Note that the filepath is extracted and not corrected. If you don't need the pathname you can omit the ExtractFilePath() from the function.)
FileUtil
function FindDiskFilename(const Filename: string): string;