Directory Path

Does anyone know how to use comdlg32.ocx to return a directory path, without a filename? Does anyone know how to do this without comdlg32.ocx? We want the user to select a working directory, not a specific file. Thanks, Simon Edited by - simonmc on 2001 Oct 09 00:47:16

The way to “misuse” the common dialog for this purpose is as follows:

var cdlg = type OCX, Microsoft Common Dialog Control 6.0
var MyDirectory = type Text, 250
var Counter = integer

//Setup Common Dialog
cdlg.DialogTitle := 'Select a directory';
cdlg.FileName := cdlg.DialogTitle;
// "Impossible" filetype shows Dirs only
cdlg.Filter := 'Directories|*.#%$';

//If Cancel was pressed, no action
IF cdlg.FileName = cdlg.DialogTitle THEN EXIT;

//Strip filename from path
MyDirectory :=cdlg.FileName;
Counter := STRLEN(MyDirectory) + 1;
  IF MyDirectory[Counter] <> '\' THEN
    Counter -= 1
    MyDirectory := COPYSTR(MyDirectory,1,Counter);
    Counter := 0;
UNTIL Counter = 0;


Note that you need to have, for development, an MS Common Dialog control from a programming environment, such as Visual Basic. A small drawback of this tricky method is that the filename box of the common dialog should not be empty, or the “Save” button will not work. To do this directory selection without using the common dialog, you can create a form based on table 2000000022 Files. Do a SETRANGE(Path,‘Your Init Dir’) and a SETRANGE(“Is a File”, False) for getting directories only. To enable browsing, you will need to write some code for expanding/shrinking the path filter, using a few buttons to imitate the common dialog functions. You will get the familiar “Navision look”, but a disadvantage is that you don’t get the standard control which users expect for file/directory selections, and you cannot create new directories. John Edited by - John Tegelaar on 2001 Oct 09 02:06:15