How to show the Windows select folder dialog and return the name of the selected folder?

The next function shows the Windows select folder dialog. It returns True if the user successfully selected a folder. Pass the string variable in which the folder name is stored as a var parameter to the function. You need to add ShlObj to the uses clause of your unit.

uses ShlObj;

function BrowseForFolder(var FolderName: String): Boolean;
var
  BrowseInfo  : TBrowseInfo;
  ItemIDList  : PItemIDList;
  DisplayName : array[0..MAX_PATH] of Char;
begin
  Result:=False;
  FillChar(BrowseInfo, SizeOf(BrowseInfo), #0);
  with BrowseInfo do
  begin
    hwndOwner:=Application.Handle;
    pszDisplayName:=@DisplayName[0];
    lpszTitle:='Select a folder';
    ulFlags:=BIF_RETURNONLYFSDIRS;
  end;
  ItemIDList:=SHBrowseForFolder(BrowseInfo);
  if Assigned(ItemIDList) then
  begin
    if SHGetPathFromIDList(ItemIDList, DisplayName) then
    begin
      FolderName:=DisplayName;
      Result:=True;
    end;
    GlobalFreePtr(ItemIDList);
  end;
end;

Source: www.guidogybels.net.