发布日期: 11/15/2021

Select a Directory or File

You can prompt the user to select a directory using the Pick Directory() function. The command displays a platform-specific window in which the user selects a folder. On Windows, the optional prompt string appears at the top of the Browse window (Windows) or below “Open” on the Finder window (macOS). You can also specify the path for an initial directory that appears, and specify whether files should appear in the Pick Directory window.

Pick Directory ( "Select a directory." );

To let the user select a file, use the Pick File() function:

Pick File(
	<"prompt message">, <"initial directory"> <{filter list}>,
	<first filter>, <save flag>, <"default file">,
	<multiple>)

The "prompt message" is used as the window title. The "initial directory" defines which folder initially appears. If a directory is defined as an empty string, the default directory is used.

You can also define the {filter list} used for the Open() window, forcing it to show only certain file types. This list must use the following syntax:

{"Label1|suffix1;suffix2;suffix3", "Label2|suffix4;suffix5"}

Each quoted string adds an entry to the File name list in the Open() window. Label defines the text that is displayed for each menu option. The following list of suffixes defines the file types that are displayed if its corresponding label is selected. Note the use of "*" to list all files in the window.

Pick File(
	"Select JMP File", // prompt message
	"$SAMPLE_DATA", // initial directory
	{"JMP Files|jmp;jsl;jrn", "All Files|*"}, // file filter list
	1, // intially selected item
	0, // doesn’t prompt the user to save the file
	"Analgesics.jmp" // file that is selected by default
);

Tip: All arguments are optional, however, they are also positional. This means that you can leave out arguments only at the end of the script. Use empty strings for the arguments that you want to omit from the beginning of the script.

The script below does not set the default directory or the default file:

Pick File(
	"Select JMP File",
	"", // no default directory
	{"JMP Files|jmp;jsl;jrn", "All Files|*"},
	1,
	0,
	"" // no default file
);

The <first filter> argument sets the default selection where n is the index for the list item. In the script above, the <first filter> is the first item in the list: "JMP Files|jmp;jsl;jrn".

If <Save Flag> is false, the Multiple argument can be added to allow the user to select multiple files using the one window:

Pick File(
	"Select JMP File",
	"",
	{"JMP Files|jmp;jsl;jrn", "All Files|*"},
	1,
	0,
	"",
	multiple // save flag is 0, allows multiple file selection
);
需要更多信息?有问题?从 JMP 用户社区得到解答 (community.jmp.com).