Solved

Directory List - Doesn't show all folders?

Posted on 2007-11-15
7
2,792 Views
Last Modified: 2008-04-09
If you drop the Delphi directorylist component on a form, and look at the directories showing on your c drive ... it does not show all the same folders as Windows explorer.  For example go to your c:\documents and settings\ folder and on mine it shows 3 folders, while in windows explorer it shows 7. How do I get this to show everything?   You can look at the dirs in dos or in explorer, but the Delphi component doesn't show them all.   I use Delphi 2007 but in earlier versions the result is still the same.
0
Comment
Question by:jexd99
7 Comments
 
LVL 19

Expert Comment

by:MerijnB
Comment Utility
are the directories hidden?
0
 
LVL 14

Expert Comment

by:SteveBay
Comment Utility
TDirectoryListbox does not show items with hidden or system atrributes.

You could modify it by changing a line FileCtrl.pas in the Delphi\source\VCL Folder

Search for:
 â€œStatus := FindFirst(SlashSep(ParentDirectory, '*.*'), faDirectory, SearchRec);”
And change it to this:
 Status := FindFirst(SlashSep(ParentDirectory, '*.*'), faDirectory or faHidden or faSysFile, SearchRec);”

Steve
0
 
LVL 14

Expert Comment

by:SteveBay
Comment Utility
.. without the weird characters:

change:
Status := FindFirst(SlashSep(ParentDirectory, '*.*'), faDirectory, SearchRec);

to:
Status := FindFirst(SlashSep(ParentDirectory, '*.*'), faDirectory or faHidden or faSysFile, SearchRec);
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:jexd99
Comment Utility
I figured for sure that would fix it.... but it didn't.  Thats strange, those folders must have some attributes set differently, 3 of the folders are hidden but that still doesn't allow them to display even after I change the filectrl.pas.  The wierd thing is if I write my own routine just scrolling through the folders, it lists all of them no problem, but that directory listbox won't list them.
0
 

Author Comment

by:jexd99
Comment Utility
Another odd thing is that I renamed filectrl.pas to 2filectrl.pas just to make sure it would get an error, and it didn't.  I don't see anywhere else where this file is getting read in from......  so I assume its pulling it in somewhere else or I should have received an error on this after recompiling.
0
 
LVL 10

Accepted Solution

by:
dinilud earned 50 total points
Comment Utility
Try this
Unit1.dfm

==========
 

object Form1: TForm1

  Left = 142

  Top = 175

  Width = 431

  Height = 346

  Caption = 'Form1'

  Color = clBtnFace

  Font.Charset = DEFAULT_CHARSET

  Font.Color = clWindowText

  Font.Height = -11

  Font.Name = 'MS Sans Serif'

  Font.Style = []

  OldCreateOrder = False

  PixelsPerInch = 96

  TextHeight = 13

  object DirectoryListBox1: TDirectoryListBox

    Left = 0

    Top = 0

    Width = 423

    Height = 312

    Align = alClient

    ItemHeight = 16

    TabOrder = 0

  end

end
 
 

Unit1.pas

==========
 

unit Unit1;
 

interface
 

uses

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

  Dialogs, StdCtrls, FileCtrl;
 

type

  TDirectoryListBox=class(FileCtrl.TDirectoryListBox)

  protected

    procedure BuildList; override;
 

    function ReadDirectoryNames(const ParentDirectory: string;

                                           DirectoryList: TStringList): Integer;

  end;
 
 
 

  TForm1 = class(TForm)

    DirectoryListBox1: TDirectoryListBox;

  private

    { Private declarations }

  public

    { Public declarations }

  end;
 

var

  Form1: TForm1;
 

implementation
 

{$R *.dfm}
 

function SlashSep(const Path, S: String): String;

begin

  if AnsiLastChar(Path)^ <> '\' then

    Result := Path + '\' + S

  else

    Result := Path + S;

end;
 

function TDirectoryListbox.ReadDirectoryNames(const ParentDirectory: string;

  DirectoryList: TStringList): Integer;

var

  Status: Integer;

  SearchRec: TSearchRec;

begin

  Result := 0;

  Status := FindFirst(SlashSep(ParentDirectory, '*.*'), faAnyFile xor faSysFile, SearchRec);

  try

    while Status = 0 do

    begin

      if (SearchRec.Attr and faDirectory = faDirectory) then

      begin

        if (SearchRec.Name <> '.') and (SearchRec.Name <> '..') then

        begin

          DirectoryList.Add(SearchRec.Name);

          Inc(Result);

        end;

      end;

      Status := FindNext(SearchRec);

    end;

  finally

    FindClose(SearchRec);

  end;

end;
 

procedure TDirectoryListBox.BuildList;

var

  TempPath: string;

  DirName: string;

  IndentLevel, BackSlashPos: Integer;

  VolFlags: DWORD;

  I: Integer;

  Siblings: TStringList;

  NewSelect: Integer;

  Root: string;

  PPreserveCase,PCaseSensitive:PBoolean;

begin

  try

    Items.BeginUpdate;

    Items.Clear;

    IndentLevel := 0;

    Root := ExtractFileDrive(Directory)+'\';

    GetVolumeInformation(PChar(Root), nil, 0, nil, DWORD(i), VolFlags, nil, 0);
 

    pPreserveCase:=@PreserveCase;

    PCaseSensitive:=@CaseSensitive;
 

    pPreserveCase^ := VolFlags and (FS_CASE_IS_PRESERVED or FS_CASE_SENSITIVE) <> 0;

    PCaseSensitive^ := (VolFlags and FS_CASE_SENSITIVE) <> 0;
 

    if (Length(Root) >= 2) and (Root[2] = '\') then

    begin

      Items.AddObject(Root, OpenedBMP);

      Inc(IndentLevel);

      TempPath := Copy(Directory, Length(Root)+1, Length(Directory));

    end

    else

      TempPath := Directory;

    if (Length(TempPath) > 0) then

    begin

      if AnsiLastChar(TempPath)^ <> '\' then

      begin

        BackSlashPos := AnsiPos('\', TempPath);

        while BackSlashPos <> 0 do

        begin

          DirName := Copy(TempPath, 1, BackSlashPos - 1);

          if IndentLevel = 0 then DirName := DirName + '\';

          Delete(TempPath, 1, BackSlashPos);

          Items.AddObject(DirName, OpenedBMP);

          Inc(IndentLevel);

          BackSlashPos := AnsiPos('\', TempPath);

        end;

      end;

      Items.AddObject(TempPath, CurrentBMP);

    end;

    NewSelect := Items.Count - 1;

    Siblings := TStringList.Create;

    try

      Siblings.Sorted := True;

        { read all the dir names into Siblings }

      ReadDirectoryNames(Directory, Siblings);

      for i := 0 to Siblings.Count - 1 do

        Items.AddObject(Siblings[i], ClosedBMP);

    finally

      Siblings.Free;

    end;

  finally

    Items.EndUpdate;

  end;

  if HandleAllocated then

    ItemIndex := NewSelect;

end;
 
 

end.

Open in new window

0
 
LVL 14

Expert Comment

by:SteveBay
Comment Utility
Check your library path. You may be getting the DCU rather than the PAS file. You may also need to BUILD rather  than just COMPILE because FileCtrl is not part of the project.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now