fileSelector()
Opens the file selection dialog and returns the selected file name.
Synopsis
int fileSelector(string &fileName [, mapping options |
string dir = PROJ_PATH [, bool notUp = true [, string pattern = "" [, bool open
= true [, string settingsId = "" [, bool fileActions = true]]]]]])
Parameters
Parameter | Description |
---|---|
fileName | Path to the file. If you click on "OK" in the selection dialog, the file path is saved in the parameter fileName. If you click on "Cancel", an empty string is saved. |
options | Instead of passing separate optional parameters to the function, a mapping can be used. Each of the optional parameters can be used as key within the mapping, see for example: Disable File Actions Code Snippet |
dir |
Target directory for selection. Alternatively, the string can contain a path and filename. In this case the directory will be changed to that path and the filename will be selected. Note: If for the target directory a path is used which
corresponds to one of the project paths or the WinCC OA path, the combo box for drive
selection in the file selection dialog will be disabled. To
enable the drive selection a path outside of the project has to
be specified.
|
notUp | Denies the access of a directory path above the dirstr directory. if notUp is true and dirstr is e.g. ./temp/dir1/ than the user is not allowed to go to the ./temp/ directory above the target directory. |
patternstr | You can specify a pattern string to specify what kind of files should be opened, for example, "*.gif" opens gif files only. If you want to specify multiple types, the entries have to be separated by a blank, e.g. "*.xml *.ds". |
open |
Specifies whether only existing files can be selected or if new file names can be specified also. TRUE: Existing files can be selected only. FALSE: File names can be specified and not only selected. |
settingsId | Each time the file selection dialog is reopened, the window settings (position, size) are written to this ID. Thus the file selection dialog stores the information, at which position and with which windows size it was closed and thus it has to open the next time. This parameter is useful if for example two monitors are used: To prevent that the file dialog of the panel on monitor 1 is always opened on Monitor 2, the window position can be saved on a certain monitor via this ID. |
fileActions | Specifies if file operations are allowed within the file selector, e.g. create new files or folders. By default, file actions are allowed. |
Return value
In the event of an error, the function returns -1 otherwise, 0.
Errors
A message will be issued when a directory has been selected instead of a file or an incorrect parameter.
Details
Opens the file selection dialog and writes the name of a file selected there to the string variable fileName. The argument dirstr indicates from which directory the selection will be made after the dialog has been opened. The optional argument notUp, as long as it has been set to true, restricts the selection in the dialog to directories and files that exist in the directory dirstr. The default value of notUp is also true. The optional argument patternstr allows specifying what kind of files will be opened, for example, "*.gif" opens only gif files. Valid content of the variable fileName is an absolute file path string.
main()
{
string fileName;
fileSelector(fileName, PROJ_PATH + "/config",false, "*.*", false, "MyId");
DebugN("Filename:", fileName);
}
Disable File Actions Code Snippet
main()
{
mapping options = makeMapping("fileActions", false, "dir", getPath(DATA_REL_PATH));
string filename;
fileSelector(filename, options);
}
Assignment
Availability
UI