Avatar of QC20N
QC20N
Flag for Denmark asked on

Opendialog only for Folder

Hi, I'm looking for a OpenDialog but only for folders.

I need to have the user of my application to open all files from a folder with a specific extension.

How do I do that? I know the OpenDialog. But that is only for files.
Delphi

Avatar of undefined
Last Comment
Marco Gasi

8/22/2022 - Mon
Marco Gasi

You can download and install the Jedi Pack (http://www.delphi-jedi.org/) which holds tenth of useful components. There is  TJvDirectoryEdit also which does exactly what you're looking for.

Cheers
ASKER CERTIFIED SOLUTION
Marco Gasi

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Ephraim Wangoya

Use this function

 
uses
  ShlObj;

function BrowseDialogCallBack(Wnd: HWnd; uMsg: UINT; lParam, lpData: LParam): Integer stdcall;
var
  WA, R: TRect;
  PT: TPoint;
begin
  if uMsg = BFFM_INITIALIZED then
  begin
    WA := Screen.WorkAreaRect;
    GetWindowRect(Wnd, R);
    PT.X := ((WA.Right - WA.Left) div 2) - ((R.Right - R.Left) div 2);
    PT.Y := ((WA.Bottom - WA.Top) div 2) - ((R.Bottom - R.Top) div 2);
    MoveWindow(Wnd, PT.X, PT.Y, R.Right - R.Left, R.Bottom - R.Top, True);

    SendMessage(Wnd, BFFM_SETSELECTION, Ord(True), Integer(lpData));
  end;
  Result := 0;
end;

function BrowseDirectoryDialog(const ATitle: string; const AFlag: Integer;
  var Dir: string): Boolean;
var
  lpItemID: PItemIDList;
  BrowseInfo: TBrowseInfo;
  DisplayName, TempPath: array[0..MAX_PATH] of Char;
begin
  FillChar(BrowseInfo, SizeOf(TBrowseInfo), #0);
  with BrowseInfo do
  begin
    hwndOwner := Application.Handle;
    pszDisplayName := @DisplayName;
    lpszTitle := PChar(ATitle);
    ulFlags := AFlag;
    lpfn := BrowseDialogCallBack;
    lParam := Integer(PChar(Dir));
  end;

  lpItemID := ShlObj.SHBrowseForFolder(BrowseInfo);
  Result := lpItemId <> nil;
  if Result then
  begin
    ShlObj.SHGetPathFromIDList(lpItemID, TempPath);
    Dir := TempPath;
    GlobalFreePtr(lpItemID);
  end;
end;

Open in new window


Call it this way

var
  Folder: string;
begin
  Folder := 'c:\';  //initial folder
  if BrowseDirectoryDialog('Select Folder', BIF_RETURNONLYFSDIRS, Folder) then
  begin
      //your code
  end;  
end;
Marco Gasi

Excuse me, ewangoya, but why you suggest to use something else than the built in function? I ask this because I really don't uderstand where is the advantage using such a function as that you have suggested...
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck