SelectDirectory (C++)

From RAD Studio Code Examples
Jump to: navigation, search


This example uses a button and a label on a form. When you click the button, a Select Directory dialog box appears. The current directory displayed in the dialog box is C:\\Program Files\\CodeGear for VCL, and in the user's documents folder (C:\Users\<username>\Documents in Windows) for FMX. You can select a directory from the directory list or enter a new directory in the edit box. If you enter a new directory, a message box asks you if the directory should be created. If you choose Yes, the directory is created. If you choose No, the message box disappears without creating the directory. The selected name of the directory appears as the caption of the label.



#include "FileCtrl.hpp"

const SELDIRHELP = 1000;
void __fastcall TForm1::Button1Click(TObject *Sender)
  String Dir = "C:\\Program Files\\CodeGear";
  if (SelectDirectory(Dir, TSelectDirOpts() << sdAllowCreate << sdPerformCreate << sdPrompt,SELDIRHELP))
	Label1->Caption = Dir;


#include <FileCtrl.hpp>
#include <IOUtils.hpp>
void __fastcall TForm1::Button1Click(TObject *Sender)
  String Dir;
  if (SelectDirectory("Select document folder", System::Ioutils::TPath::GetDocumentsPath(), Dir))
    Label1->Text = Dir;