Results 1 to 6 of 6

Thread: Opvullen TStrings werkt niet correct

  1. #1

    Opvullen TStrings werkt niet correct

    Hallo,

    Ik moet alle bestanden in een bepaalde folder inlezen en stockeren in een Stringlist.
    Maar als ik als test de bestandsnamen toon op het scherm verschijnt er niks. Blijkbaar wordt de lijst niet opgevuld.

    Mijn code :
    Code:
    var
      Dir : string;
      SR : TSearchRec;
      DirList : TStrings;
      index : integer;
    
    ....
    
     // select main folder where files are located
      with TFileOpenDialog.Create(nil) do
        try
          Options := [fdoPickFolders];
          if Execute then
            begin
              ShowMessage(FileName);
              dir := Filename;
            end;
        finally
          Free;
        end;
    
      // loop files in the 'dir' path
      DirList := TStringList.Create;
        try
          if FindFirst(dir , faAnyFile, SR) = 0 then
              begin
                repeat
                    DirList.Add(SR.Name); //Fill the list
                until FindNext(SR) <> 0;
                FindClose(SR);
              end;
    
         // to delete : display all values to check
         for Index := 0 to DirList.Count - 1 do
          Showmessage( DirList.Strings[Index]);
    
        finally
         DirList.Free;
        end;
    Enig idee wat er verkeerd loopt?

    Alvast bedankt

    Lainkes

  2. #2
    de regel FindFirst zoekt naar filenames die voldoen aan de mask "dir", dat lijkt mij niet te kloppen https://smartpascal.github.io/help/assets/findfirst.htm

  3. #3
    Blijkbaar moest ik eerst de map aanpassen met

    Code:
     SetCurrentDir(dir);

  4. #4
    Zou niet nodig moeten zijn als dir een compleet pad bevat, maar volgens mij verwacht FindFirst wel een file mask, niet alleen de directorynaam. Ik zou verwachten dat dit werkt, zonder de current dir (= working directory) van de applicatie aan te passen.

    Code:
    if FindFirst(IncludeTrailingPathDelimiter(dir) + '*.*' , faAnyFile, SR) = 0 then
    1+1=b

  5. #5
    Fantastisch, dit werkt correct.
    Ik ben zo jaloers op jullie brein :-))

  6. #6
    FindAllFiles()?

    Bart

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •