поиск и вывод папок. delphi

Discussion in 'С/С++, C#, Rust, Swift, Go, Java, Perl, Ruby' started by firstfallen, 20 Nov 2010.

  1. firstfallen

    firstfallen New Member

    Joined:
    1 Mar 2010
    Messages:
    64
    Likes Received:
    0
    Reputations:
    0
    как организовать поиск в определённой дериктории папок и вывод их списком в листбокс?
     
  2. alexey-m

    alexey-m Elder - Старейшина

    Joined:
    15 Jul 2009
    Messages:
    518
    Likes Received:
    100
    Reputations:
    37
    Code:
    procedure ScanDir(Dir: string);
    var
      hFind: THandle;
      FD: TWIN32FindData;
    begin
      hFind:= FindFirstFile(PChar(Dir + '\*.*'), FD);
      if (hFind <> INVALID_HANDLE_VALUE) then try
        repeat
          if (FD.dwFileAttributes and faDirectory) <> 0 then
           [COLOR=DarkRed]Form1.ListBox1.Items.Add(FD.cFileName);[/COLOR]
        until not FindNextFile(hFind,FD);
      finally
        Windows.FindClose(hFind);
      end;
    end;
    
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      ScanDir('c:\');
    end;
    
     
    #2 alexey-m, 20 Nov 2010
    Last edited: 20 Nov 2010
  3. firstfallen

    firstfallen New Member

    Joined:
    1 Mar 2010
    Messages:
    64
    Likes Received:
    0
    Reputations:
    0
    шикарно. но как сделать чтобы не выводил в листбоксе точки (. и ..) в самом начале?
     
  4. _nic

    _nic Elder - Старейшина

    Joined:
    5 May 2006
    Messages:
    651
    Likes Received:
    54
    Reputations:
    3
    ТС тебе не стыдно?Учи рекурсию, и работу со строками!
     
  5. alexey-m

    alexey-m Elder - Старейшина

    Joined:
    15 Jul 2009
    Messages:
    518
    Likes Received:
    100
    Reputations:
    37
    самому-то подумать сложно? все же просто:

    Code:
      .............
      hFind:= FindFirstFile(PChar(Dir + '\*.*'), FD);
      if (hFind <> INVALID_HANDLE_VALUE) then begin
        repeat
          if (FD.cFileName<>String('.')) and (FD.cFileName <> '..') then begin
            if (FD.dwFileAttributes and faDirectory) <> 0 then
            .............
    
     
  6. firstfallen

    firstfallen New Member

    Joined:
    1 Mar 2010
    Messages:
    64
    Likes Received:
    0
    Reputations:
    0
    подкинь сайтик со статьями и примерами(учебники не над)
     
  7. 0pTik

    0pTik Banned

    Joined:
    18 Jul 2010
    Messages:
    240
    Likes Received:
    85
    Reputations:
    17

    Вот тут много примеров , да и форум хороший

    http://www.cyberguru.ru/
     
  8. slesh

    slesh Elder - Старейшина

    Joined:
    5 Mar 2007
    Messages:
    2,702
    Likes Received:
    1,224
    Reputations:
    455
    скачиваешь 5005 статей по делфи (она же Delphi World) и там очень много примеров на всё
     
  9. Maestorf

    Maestorf New Member

    Joined:
    18 Nov 2010
    Messages:
    1
    Likes Received:
    1
    Reputations:
    0
    Спасибо..тоже почитаю)))
     
  10. GhostOnline

    GhostOnline Active Member

    Joined:
    20 Dec 2008
    Messages:
    723
    Likes Received:
    110
    Reputations:
    22
    Намного удобней юзать IOUtils из Delphi 2010