Forum > Beginners

Findallfiles question

(1/2) > >>

Ten_Mile_Hike:
I know that the following code doesn't use Try/Finally or create/free a Tstringlist.
It is just a simple example to get my question across.

The procedure below finds only 1345 *.txt files on my C: drive
but the excellent freeware program "Everything" finds 2232 *.txt files there.
Investigation finds that my code can not parse certain folders on my drive.
I assume that this is because of "Permissions". I have tried running the
executable outside of Lazarus "as admin", with no help.

HOW CAN I LIST ALL 2232 FILES ON MY C: DRIVE LIKE "EVERYTHING" DOES?

Latest Laz/FPC release, Win 11

procedure TForm1.Button1Click(Sender: TObject);
begin
  memo1.Lines  := FindAllFiles('.\C:\', '*.txt', True);
end; 


Thank You

KodeZwerg:
Be aware that tools like "Everything" also list archive or cache/temp folder data ...
Untested, just written in here so there might be errors.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function FindFiles(const Path, Mask: string): TStringList;var  SearchRec: TSearchRec;  CurrentPath: string;begin  Result := TStringList.Create;  try    if Path[Length(Path)] <> '\' then      CurrentPath := Path + '\'    else      CurrentPath := Path;     if FindFirst(CurrentPath + Mask, faAnyFile, SearchRec) =  0 then    begin      repeat        Result.Add(CurrentPath + SearchRec.Name);      until FindNext(SearchRec) <>  0;      FindClose(SearchRec);    end;     if FindFirst(CurrentPath + '*', faDirectory, SearchRec) =  0 then    begin      repeat        if (SearchRec.Attr and faDirectory <>  0) and (SearchRec.Name <> '.') and (SearchRec.Name <> '..') then          Result.AddStrings(FindFiles(CurrentPath + SearchRec.Name, Mask));      until FindNext(SearchRec) <>  0;      FindClose(SearchRec);    end;  except    Result.Free;    raise;  end;end;I guess the TStringList handling must be outsourced, right now it destroy itself I think :D

Ten_Mile_Hike:
KodeZwerg,

Thank You. I will play with this this tomorrow.
I am surprised and relieved that it was not a
Windows "Permissions"/"Ownership" thingy.

TRon:
@Ten_Mile_Hike:
I do not know the program you refer to but a quick glance at their webpage seem to suggest that the program is able to export a filelist (does require the program can export filenames with their full path).

Do export and then load the produced list into a stringlist. Then use the code from KodeZwerg to create a simlar list (full paths included) and load that into another stringlist. Now you can compare the two lists and try to determine which files are missing (if any). Make sure to allow for the stringlist to accept duplicates. (brain-farth, see also below. Thx for noticing Zvoni)

Instead of KodeZwerg's code you could also check against the findallfiles results from you own code.

Bart:
Well, I tried similar (for stress testing) and got an exception because FindAllFiles tried to access folders it wasn't supposed to.
So that's gonna be an issue.

Bart

Navigation

[0] Message Index

[#] Next page

Go to full version