Forum > Editor

Library routine for returning the exact name for a case-insensitive filename?

(1/2) > >>

vfclists:
 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:

--- 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?

--- End quote ---
All file related routines for FPC/Lazarus preserve filename case as it is a filesystem/OS related matter.

rvk:

--- 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?

--- End quote ---
Not sure if there is a ready made function.
But you could use something like this:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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.)

vfclists:

--- Quote from: rvk on July 06, 2016, 07:53:56 pm ---
--- 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?

--- End quote ---
Not sure if there is a ready made function.
But you could use something like this:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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.)

--- End quote ---

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:
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.   

Navigation

[0] Message Index

[#] Next page

Go to full version