Recent

Author Topic: Pathname conversion  (Read 1514 times)

Kaller

  • Jr. Member
  • **
  • Posts: 72
Re: Pathname conversion
« Reply #15 on: August 31, 2023, 02:33:27 am »
Case sensitivity is a processing distinction, not a fact about files.  Files themselves do have case structure and it can be significant when migrating files between systems.  Mario's answer is nice  because it doesn't involve the app changing the current directory just to determine the actual case on disk.  I reproduce below the English version courtesy of GPT. It doesn't require changing the  current folder. 

« Last Edit: August 31, 2023, 04:47:03 am by Kaller »

Bogen85

  • Hero Member
  • *****
  • Posts: 595
Re: Pathname conversion
« Reply #16 on: August 31, 2023, 04:05:12 am »
Case sensitivity is a processing distinction, not a fact about files.  Files themselves do have case structure and it can be significant when migrating files between systems.  Mario's answer is nice  because it doesn't involve the app changing the current directory just to determine the actual case on disk.  I reproduce here the English version courtesy of GPT. It doesn't require changing the  current folder. 
...

Could you please put code between the

Code: Pascal  [Select][+][-]
  1. // code here
  2.  

[code=pascal]
 // code here
[/code]

code tags on this forum?  (regular ASCII brackets, not Unicode brackets) (see the [#]button in the formatting toolbar)

As far as GPT goes, well, best to make sure it works and not necessarily advertise the fact, use and promotion of GPT on these forums often results in reactions you might find either annoying or unpleasant, and everything in between...

Kaller

  • Jr. Member
  • **
  • Posts: 72
Re: Pathname conversion
« Reply #17 on: August 31, 2023, 04:44:36 am »
The code is Mario's I just translated it and gave it some minor tweaks.  Yes I tested it before hand and appears to work very well.   I wasn't sure how to mark it up so now I know :)
Code: Pascal  [Select][+][-]
  1. procedure GetDiskFileName(var RealSourceName: String);
  2. var
  3.   InputFileName, OutputFileName: String;
  4.   MatchFound: TFilenameCaseMatch;
  5. begin
  6.   InputFileName := RealSourceName;
  7.   OutputFileName := '';
  8.  
  9.   while InputFileName <> '' do begin
  10.     {$IFDEF MSWINDOWS}
  11.       if (Length(InputFileName) = 3) and (InputFileName[2] = ':') then
  12.       begin
  13.         OutputFileName := UpperCase(ExtractFileDrive(InputFileName)) + OutputFileName;
  14.         InputFileName := '';
  15.       end;
  16.     {$ELSE}
  17.       if InputFileName = PathDelim then
  18.       begin
  19.         OutputFileName := PathDelim + OutputFileName;
  20.         InputFileName := '';
  21.       end;
  22.     {$ENDIF}
  23.  
  24.     if InputFileName <> '' then
  25.     begin
  26.       OutputFileName := ExtractFileName(ExpandFileNameCase(InputFileName, MatchFound)) + OutputFileName;
  27.       if Pos(PathDelim, InputFileName) > 0 then
  28.         OutputFileName := PathDelim + OutputFileName
  29.       else
  30.         InputFileName := '';
  31.       InputFileName := ExtractFileDir(InputFileName);
  32.     end;
  33.   end;
  34.  
  35.   RealSourceName := OutputFileName;
  36. end;
  37.  


Zvoni

  • Hero Member
  • *****
  • Posts: 2032
Re: Pathname conversion
« Reply #18 on: August 31, 2023, 08:46:49 am »
[…] The Windows Filesystem
“The Windows Filesystem”? Jesus Christ.
Right. You got me there  :D :D :D

Case-Insensitive […]
Meanwhile NTFS does support case-sensitive filenames. You will need to traverse the entire path checking each directory whether it has case-sensitive filename support enabled.

Since when????
You mean to tell me, that on NTFS (if activated) "c:\TEMP" <> "c:\temp"?
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Thaddy

  • Hero Member
  • *****
  • Posts: 13243
Re: Pathname conversion
« Reply #19 on: August 31, 2023, 10:32:00 am »
Since when????
You mean to tell me, that on NTFS (if activated) "c:\TEMP" <> "c:\temp"?
Quote:
"The NTFS file system is case-sensitive. This means that files with the same name but different case are treated as distinct files. However, the Windows API presents an abstraction of NTFS that makes it appear as a case-preserving file system. This means that the API remembers the filename case, but it does not distinguish between files whose names only differ in case.

If you want to enable case sensitivity for a folder in NTFS, you can use the fsutil.exe tool to set the folder’s content as case-sensitive."

So yes, the NTFS file system itself is case sensitive, but the Windows API abstracts that away. And can be mitigates by fsutil.
This dates back from the days that Windows pro versions were POSIX compliant by default, so since the introduction of NTFS. NTFS on Linux file names are always treated as case sensitive.

The command is: fsutil file setcasesensitiveinfo <option>
« Last Edit: August 31, 2023, 10:58:37 am by Thaddy »
I actually get compliments for being rude... (well, Dutch, but that is the same)

Zvoni

  • Hero Member
  • *****
  • Posts: 2032
Re: Pathname conversion
« Reply #20 on: August 31, 2023, 10:55:07 am »
Since when????
You mean to tell me, that on NTFS (if activated) "c:\TEMP" <> "c:\temp"?
Quote:
"The NTFS file system is case-sensitive. This means that files with the same name but different case are treated as distinct files. However, the Windows API presents an abstraction of NTFS that makes it appear as a case-preserving file system. This means that the API remembers the filename case, but it does not distinguish between files whose names only differ in case.

If you want to enable case sensitivity for a folder in NTFS, you can use the fsutil.exe tool to set the folder’s content as case-sensitive."

So yes, the NTFS file system itself is case sensitive, but the Windows API abstracts that away. And can be mitigates by fsutil.
This dates back from the days that Windows pro versions were POSIX compliant by default, so since the introduction of NTFS. NTFS on Linux file names are always treated as case sensitive.
Thx Thaddy.
So in a nutshell: The Default is "not activated", meaning that 99.9999% of all users of NTFS on Windows, think it's case-sensitive, while de facto it's not, because Windows "cheats" the "Case" away
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Thaddy

  • Hero Member
  • *****
  • Posts: 13243
Re: Pathname conversion
« Reply #21 on: August 31, 2023, 10:59:12 am »
I added:
fsutil file setcasesensitiveinfo <option>
And yes, 99.9999 % of Windows users do not know about that.... It is basically confined to sysops.
So it is no wonder you thought otherwise.

Maybe time for a poll about who ever uses fsutil?  O:-)
« Last Edit: August 31, 2023, 11:05:42 am by Thaddy »
I actually get compliments for being rude... (well, Dutch, but that is the same)

PascalDragon

  • Hero Member
  • *****
  • Posts: 5277
  • Compiler Developer
Re: Pathname conversion
« Reply #22 on: September 03, 2023, 06:28:01 pm »
Since when????
You mean to tell me, that on NTFS (if activated) "c:\TEMP" <> "c:\temp"?
Quote:
"The NTFS file system is case-sensitive. This means that files with the same name but different case are treated as distinct files. However, the Windows API presents an abstraction of NTFS that makes it appear as a case-preserving file system. This means that the API remembers the filename case, but it does not distinguish between files whose names only differ in case.

If you want to enable case sensitivity for a folder in NTFS, you can use the fsutil.exe tool to set the folder’s content as case-sensitive."

So yes, the NTFS file system itself is case sensitive, but the Windows API abstracts that away. And can be mitigates by fsutil.
This dates back from the days that Windows pro versions were POSIX compliant by default, so since the introduction of NTFS. NTFS on Linux file names are always treated as case sensitive.
Thx Thaddy.
So in a nutshell: The Default is "not activated", meaning that 99.9999% of all users of NTFS on Windows, think it's case-sensitive, while de facto it's not, because Windows "cheats" the "Case" away

Please note that the per-directory case-sensitivity was only added fearly recently to improve support for WSL. Directories with case-sensitivity enabled have the problem that they can't be shared as network shares (if the root of the share has it enabled Windows will cancel the connection to it, if it's a sub directory, you can't enter it).

Before this time NTFS already had the ability to use the POSIX namespace which is part of NTFS from the beginning due to Microsoft supporting a POSIX subsystem in Windows NT (which was replaced with Interix in Windows 2000 I think and with Services for Unix Applications in Windows Vista or 7 only to be dropped again in 8). This also allowed to create case sensitive files that the Explorer could display, but that the Windows API handled incorrectly (so you could only view/edit the contents of the first file). If you accessed them using the POSIX subsystem (or Interix or SUA) then it worked correctly.

Also NTFS' default usage in Windows is considered “case preserving”, not “case sensitive” and users are aware of that, because they know that they can't create a new entry with a name that only differs in casing from an already existing entry in the same directory. So no “cheating” there. It simply works as advertised.

 

TinyPortal © 2005-2018