Skip to main content

Dialog box to select a folder, not file

Currently I have the following interface (see attached picture).
My IDEA script is attached.
It is a simple code that allows the user to select a file. However, it uses the IDEA dialog to choose a file in the current IDEA directory.
What I want is that a "Windows dialog box" is opened and that the user can select a path to a folder. How can I do this? So at the moment I can only select a single file that lies in the current IDEA working directory. I want a "usual" Windows dialog box that allows the user to navigate to a specific folder and select a folder, not a file. (It would be nice if the Windows dialog box default directory is the working directory, so the user is already in the working directory when the dialog box opens.).

Bert_B Tue, 04/11/2023 - 05:22

So with "usual Windows dialog box" I mean the same as when I want to import for example a csv / txt file. When I use the IDEA import button a dialog box opens which looks like the usual Windows dialog box. (and I want to have this to select a path.). Currently the dialog box which opens is a different one:
 
1. it is limited to my project folder - so it only allows me to navigate to a file within my current project - and
2. only allows to select a single file.

Brian Element Sun, 04/16/2023 - 07:22

Hi Bert,

When working with IDEAScript it is good to learn to use the IDEAScript browser as it has all the information on the IDEAScript commands.  One of them relates to the Open and Save dialogs that you can use to get the filename of a file you want to open, IDEAScript uses the Windows open dialog.  Here is some information on it from the browser:

CommonDialogs.FileOpen

Displays the Windows Open dialog box to let users select an existing file.

Syntax

CommonDialogs.FileOpen(defFileExt, fileName, filter)

Parameters

[in] defFileExt

The default filename extension. If the user does not include a file name extension in the Filename edit box, the extension specified by defFileExt is automatically appended to the filename. If this parameter is "", no filename extension is appended.

[in] fileName

The initial filename that appears in the Filename edit box. If this parameter is "", no filename initially appears.

[in] filter

A series of string pairs that specify filters you can apply to the file. If you specify file filters, only selected files appear in the Files list box. The first string in the string pair describes the filter and the second string indicates the filename extension to use. Multiple file name extensions can be specified by using a semicolon (;) as the delimiter. The string ends with two pipe characters (||) followed by a null character (").

Return Value

String

The full path for the selected file that the user chose in the Open dialog box.

Remarks

In the Open dialog box, file filters are displayed in a drop-down list beside the File name field. The user can select a filter to only display files with the corresponding file name extension.

Type

Method

Example

Sub Main

' Declare variables and objects.

Dim filename As String

Dim obj As Object

' Access the CommomDialogs object.

Set obj = Client.CommonDialogs

' Show the Open dialog box with the applied filters.

filename = obj.FileOpen("","","IDEA Database Files (*.IMD|*.IMD|Chart Files (*.xlc)|*.xlc|Worksheet Files (*.xls; *.xlsx)|*.xls; *.xls|Data Files (*.xlc; *.xls; *.xlsx)|*.xlc; *.xls; *.xlsx|All Files (*.*)|*.*||;")

' Display the selected file name.

MsgBox filename

' Clear the memory.

Set obj = Nothing

Set db = Nothing

End Sub