Forum > General
[SOLVED] FindAllFiles - should it detect hidden files?
Gizmo:
A user has reported to me that my program (which finds all files from a given root directory location) seems to not find hidden files.
I tried it myself using the Linux version of my program (not yet tried the Windows one but I assume it will be the same) and he is surely correct. Any files in hidden directories (ones such as ~/.ThisDir) are not detected.
AFAIK, FindAllFiles utilises FindFirst and FindNext, which, if they are the same as Delphi (http://www.delphibasics.co.uk/RTL.asp?Name=FindFirst), have the faHiddenFile attribute. I assumed that faAnyFile will return any file, hidden or not. Is that not the case?
--- Code: ---var
TotalFilesToExamine : TStringList;
...
TotalFilesToExamine := FindAllFiles(DirPath, '*', True); // assumed would return all files, hidden or not?
--- End code ---
Do I need to adjust it to TSearchRec?
Freepascal 2.6.4 and Lazarus 1.2.6
Thanks
bylaardt:
you must have permissions to access this files.
try run your program as admin.
Gizmo:
No joy. Ran as sudo - same result as before. I have tried that before. Besides, in this case, the files are all in my home dir so I have access to all of them.
howardpc:
FindAllFiles uses faAnyFile as the default FileAttribute property for the TFileSearcher class used in its implementation. This means it lists hidden files along with read-only, system files etc.
If hidden files are not shown it must be for some reason unrelated to the fact that they have the attribute faHidden (i. e. it is coincidental that they are hidden - this is not the immediate cause of the fact they are not listed). At the lowest level, LCL/FCL file routines call the OS routines, but wrapped in high level class the LCL does not show errors relating to individual file discovery. Any such errors are silently discarded.
FindAllFiles also uses faDirectory as the default for its DirectoryAttribute property. Perhaps this disallows hidden directories on Linux?
engkin:
--- Quote from: Gizmo on December 07, 2014, 10:57:30 pm ---I tried it myself using the Linux version of my program (not yet tried the Windows one but I assume it will be the same) and he is surely correct. Any files in hidden directories (ones such as ~/.ThisDir are not detected.
--- End quote ---
I don't see your code regarding the path you mentioned "~/.ThisDir". Did you use ExpandFileName before passing it to FindAllFiles?
The reason, IIRC, is that Linux does not know much about the tilde character "~", the shell does. This is to make sure your test is correct.
Navigation
[0] Message Index
[#] Next page