Library routine for returning the exact name for a case-insensitive filename? lazarus / 9-Editor ---------------------------------------------------------------------- vfclists · 2016-07-06 17:09 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? ---------------------------------------------------------------------- molly · 2016-07-06 17:39 Quote from: vfclists on July 06, 2016, 07:09:58 pm 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. ---------------------------------------------------------------------- rvk · 2016-07-06 17:53 Quote from: vfclists on July 06, 2016, 07:09:58 pm 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: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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: TOb ject);begin Showmessage(GiveCorrectCaseFileName('c:\temp\TeSt.tXt'));e nd; (Note that the filepath is extracted and not corrected. If you don't need the pathname you can omit the ExtractFilePath() from the function.) ---------------------------------------------------------------------- vfclists · 2016-07-06 18:52 Quote from: rvk on July 06, 2016, 07:53:56 pmQuote from: vfclists on July 06, 2016, 07:09:58 pm 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: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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: TOb ject);begin Showmessage(GiveCorrectCaseFileName('c:\temp\TeSt.tXt'));e nd; (Note that the filepath is extracted and not corrected. If you don't need the pathname you can omit the ExtractFilePath() from the function.) I was considering something along this line. Does Windows have a value such as the inode of Linux which can be used to obtain the exact filename and other details about a file? ---------------------------------------------------------------------- derek.john.evans · 2016-07-06 20:13 FileUtil function FindDiskFilename(const Filename: string): string; // Searches for the filename case on disk. // The file must exist. // For example: //   If Filename='file' and there is only a 'File' then 'File' will be returned. ---------------------------------------------------------------------- vfclists · 2016-07-12 04:42 Quote from: Geepster on July 06, 2016, 10:13:37 pmFileUtil function FindDiskFilename(const Filename: string): string; Thanks ---------------------------------------------------------------------- Kaller · 2021-10-18 06:36 ExpandFileNameCase function will return the full path as on disk case type TFilenameCaseMatch = (  mkNone, No file was found mkExactMatch, The filename can be used to refer to a file on the system (findfirst will find it). mkSingleMatch, Exactly one match was found, but case didn't match. mkAmbiguous More than one file will match the filename in a case- insensitive way