Solved

Directory List - Doesn't show all folders?

Posted on 2007-11-15
7
2,801 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
ID: 20289200
are the directories hidden?
0
 
LVL 14

Expert Comment

by:SteveBay
ID: 20289576
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
ID: 20289602
.. without the weird characters:

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

to:
Status := FindFirst(SlashSep(ParentDirectory, '*.*'), faDirectory or faHidden or faSysFile, SearchRec);
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:jexd99
ID: 20295675
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
ID: 20295767
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
ID: 20296731
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
ID: 20297649
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
problem when i try to pack my dll file with upx 9 71
TVirtualStringTree  search using TEdit 7 106
delphi prevent click fast 2 189
Delphi and Access based Enumeration 9 47
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

910 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

21 Experts available now in Live!

Get 1:1 Help Now