I am trying to list all the directories in this directory. I have this code:
var srec: TSearchRec; begin // folder is some absolute path of a folder if FindFirst(folder + PathDelim + '*', faDirectory, srec) = 0 then try repeat if (srec.Name <> '.') and (srec.Name <> '..') then ShowMessage(srec.Name); until FindNext(srec) <> 0; finally FindClose(srec); end;
But for some reason, I get messages about file names, not just directories. I thought using faDirectory would make FindFirst and family would return directory names. What am I doing wrong? If I change it to
if FindFirst(folder, faDirectory, srec) = 0 then
Then it displays only the name folder , but not as an absolute path (relative to folder + '/..' ) and after that it terminates.
I understand that I can check if this is a directory, making sure (srec.Attr and faDirectory) = faDirectory , but I feel like I am doing things in a workaround, and there should be a proper way to do this.
source share