I have a utility that hashes files either by directory, or by individual name. (It can also provide a hash of text.)
For the directory enumeration, I am using
FindAllFiles successfully.
https://www.freepascal.org/docs-html/rtl/sysutils/findfirst.htmlFor the individual file hashing, I was using
if FileExists to determine if it was a legitimate file, and if not, just return the hash of the text of the name.
https://www.freepascal.org/docs-html/rtl/sysutils/fileexists.htmlWell, it turns out that for some files -- primarily locked files -- it won't find them at all. Files such as \pagefile.sys or \swapfile.sys (which, I agree, we rarely really need to hash those monstrous files) were not working.
Here's the test file:
Program Lesson2;
{ This program demonstrates the FileGetAttr function }
Uses sysutils;
Procedure Testit (Name : String);
Var F : Longint;
Begin
if FileExists(Name)
then Write(Name, ' DOES exist!')
else Write(Name, ' does NOT exist!');
F:=FileGetAttr(Name);
If F<>-1 then
begin
Writeln ('Testing : ',Name);
If (F and faReadOnly)<>0 then
Writeln ('File is ReadOnly');
If (F and faHidden)<>0 then
Writeln ('File is hidden');
If (F and faSysFile)<>0 then
Writeln ('File is a system file');
If (F and faVolumeID)<>0 then
Writeln ('File is a disk label');
If (F and faArchive)<>0 then
Writeln ('File is archive file');
If (F and faDirectory)<>0 then
Writeln ('File is a directory');
end
else
Writeln ('Error reading attributes of ', Name);
Writeln;
end;
begin
testit ('ex40.pp');
testit (ParamStr(0));
testit ('C:\Pagefile.sys');
testit ('C:\Temp\ThisFileIsHidden.TXT');
testit ('C:\Temp\TestOutput.TXT');
testit ('C:\swapfile.sys');
testit ('C:\bootmgr');
testit ('C:\boot.ini');
testit ('.');
testit ('/');
End.
It didn't work with
FileGetAttr, either.
I still don't know why, but I went with
FindFirst as a replacement, and that has gone rather well.
Should that failure of
FileExists be considered a bug?