0

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

alancc
  • 487
  • 2
  • 24
  • 68
  • 2
    Use the second overload and the browse dialog will conform with control panel settings. You can't effect the first overload, the directory list is build with FindFirst[Next] calls having only faDirectory hardcoded as Attr parameter. – Sertac Akyuz Sep 15 '19 at 23:07
  • @SertacAkyuz Does the second version of SelectDirectory support to create a directory if it is not existing? – alancc Sep 16 '19 at 23:56

1 Answers1

1

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;
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Does the new version of SelectDirectory support to create a directory if it is not existing? – alancc Sep 16 '19 at 23:55
  • 1
    @alancc Yes, if you enable the `sdNewUI` and `sdNewFolder` flags in the `Options` parameter. [Read the documentation](http://docwiki.embarcadero.com/Libraries/XE3/en/Vcl.FileCtrl.SelectDirectory). – Remy Lebeau Sep 17 '19 at 00:29
  • I read the document and still have many questions, 1 "When using this syntax, SelectDirectory does not change the value of the current directory.", does "currrent directory" means the value returned by GetCurrentDirectory() Windows API? 2. Whether the second version works on different Windows platforms. I cannot find a list of supported Windows systems. – alancc Sep 18 '19 at 00:07
  • 1. yes. 2. it uses the `SHBrowseForFolder()` API internally, which is available on all Windows platforms from Win95 onward. – Remy Lebeau Sep 18 '19 at 00:10
  • Thank you, Remy. I just make some more tests and write something undocumented in Delphi help here: 1. When Root is empty string '', then the dialog will show the full set of the folder tree in the computer, 2. The initial value of Directory will make that directory being selected when the dialog is shown. Correct me if there are anything wrong. Thank you very much. – alancc Sep 18 '19 at 02:41