Search code examples
delphidirectoryhidden-files

How to Let Delphi SelectDirectory Show Hidden Directory and Files?


I am using Delphi XE3.

When invoking SelectionDirectory, as below:

Dir := '';
SelectDirectory(Dir, [], 0);

I find the pop up "Select Directory" dialog will not show hidden folders and files. Is there a way to show them?

THanks


Solution

  • You are using the old version of SelectDirectory() that displays a custom VCL TForm that uses a Windows 3.1 style UI and searches folders/files manually without regard to the user's settings. That version of SelectDirectory() does not support what you want, it will not display hidden items.

    Use the newer overloaded version of SelectDirectory() instead. It displays a system-provided dialog for browsing folders/files that respects the user's settings. It will show hidden items if that is how the user has configured Explorer.

    procedure TForm1.Button1Click(Sender: TObject);
    var
      Dir: string;
    begin
      SelectDirectory('Caption', '', Dir, [], Self);
    end;