[fpc-pascal] [Windows] FileGetAttr reports faHidden on e.g. C:\

José Mejuto joshyfun at gmail.com
Fri Mar 6 01:05:25 CET 2015


El 04/03/2015 a las 16:01, Bart escribió:
> Hi,
> Kind of off-topic.
> While working on Lazarus' TShellTreeView component, it was brought to
> my attention that FileGetAttr('C:\') returns an attribute that has
> faHidden in it.
> This is kind of unexpected.
> Well actually it reports $16: faDirectory + faHidden + faSysFile on
> Win7-64 (32-bit fpc)
> On Win98SE it reports $10: faDirectory.
> On Win7 FileGteAttr reports $16 on any path that is the root of a
> drive, unless it is a 'substituted" drive (subst X: path/to/folder).
> Does anybody know when this behaviour of Windows changed, and why?
Hello,

That difference is between FAT and NTFS. In NTFS "C:\" is not a 
directory, it is a drive and it also holds data references about the 
media it contents. Of course it could be considered a folder but it can 
not be used as a reparse point (like folders), you can not RMDIR it and 
other differences. Also the path "C:\" refers to folder "C:" which 
enters in conflict because "C:" is the notation for current process 
folder not "C:\".

Resume, in Windows "[OneLetter]:\" is a drive which mostly works at 99% 
as a folder, but it is not, and its attributes does not have the same 
meaning as a regular folder and it should be operated as a drive concept 
(no attributes).

Side note: Programming of "FileExists" and "DirectoryExists" should be 
changed (rethink, retest,...) in 32 bits Windows programs in a 64 bit 
platform as GetFileAttributes does not perform the virtual aliasing like 
"Program Files" -> "Program Files (x86)" and a call to "FileExists" (32 
bits) could report that a file exists that could not be opened because 
it exists in the one that "FileExists" can see but not in the one that 
would "FileCreate" try to use.

Jose Mejuto



More information about the fpc-pascal mailing list