Hierarchical File Selector Library
The Hierarchical File Selector Library is a single Analytica file, Hierarchical file selector.ana, that lets users pick a file or a folder from a nested pop-up menu instead of typing a path. You enter a starting folder, and the library builds a Choice menu whose submenus mirror the folders beneath it. Each selection returns a path relative to the starting folder and a full absolute path that the rest of your model can use.
Typical uses
- Let end users choose an input data file (CSV, Excel, text) from a project folder without typing its path.
- Let users choose an output folder for files your model writes.
- Offer several independent file or folder pickers in one model, each with its own starting folder.
- Browse a deep folder tree where a flat list of files would be too long to scan.
Download
- Hierarchical file selector.ana — the library.
Requirements
- Analytica 6.4 or later, which added the «labels», «selectionLabels» and «nestUnder» parameters of Choice. The library was saved with Analytica 7.1.
- Windows-style paths. Relative paths are built with
\separators.
Getting started
- Add the library to your model with File > Add Module, or open it directly.
- Open Try sample menu to see how the nested menu behaves. It uses six sample paths, so none of the files needs to exist.
- In Starting folder, enter the full path of a folder you can access, for example
C:\Users\me\Documents\Data. - Open Select file and work down through the submenus to a file.
- Use Selected full path in your model, for example as the file name passed to ReadTextFile or ReadFromExcel.
To choose a folder instead, use Select folder and Selected full folder.
Step by step (the front panel)
Step 1. Enter a starting folder
- Starting folder is the full path of the folder to browse. It is blank by default, and every menu shows <Enter a starting folder> until you fill it in.
- The menus include everything beneath this folder, except hidden files and folders.
- After changing the starting folder, reselect your file and folder.
Step 2. Set the item limit
- Maximum items caps how much of the folder tree each scan reads. The default is 1000. It must be a positive whole number.
- For the file menu, visible files and folders count toward the limit together. For the folder menu, only descendant folders count; the starting folder itself does not.
- If a scan finds more than the limit, it stops, and the menu shows a single limit message instead of a partial list. Raise the limit or choose a narrower starting folder.
- Large limits can make a menu slow to open, especially on network drives.
Step 3. Select a file
- Select file lists every visible file beneath the starting folder. Each folder is a submenu; each file appears under its own name.
- After you select a file, the box shows its full relative path, such as
Projects\Alpha\Inputs\data.xlsx, so files with the same name in different folders stay distinct. - Folders with no files anywhere beneath them do not appear.
- Selected full path returns the absolute path, or Null when the menu is only showing a message.
Step 4. Select a folder
- Select folder lists the starting folder and every visible folder beneath it.
- A folder without subfolders is a plain menu item: click it to select it.
- A folder with subfolders is a submenu: open it and choose <Select this folder> to select that folder itself.
- The value is a relative path, where
.means the starting folder. Selected full folder returns the absolute path, or Null.
Step 5. Refresh and reselect
- Menu contents are cached. After adding, removing or renaming files on disk, click Refresh lists.
- A Choice stores the position of the selected item, not its text. After you refresh, change the starting folder or change Maximum items, the same position can point to a different item. Always reselect after any of these.
Reusable selectors
The library includes two self-contained modules for models that need more than one picker. Each has its own starting folder, menu, full-path result and refresh button. Both share the library's Maximum items setting.
| Module | Starting folder | Result to reference | Refresh button |
|---|---|---|---|
| Reusable file selector | File_selector_start |
File_selector_full_path |
Refresh files |
| Reusable folder selector | Folder_selector_start |
Folder_selector_full_path |
Refresh folders |
- The reusable file selector also lists empty folders. A folder with no files and no subfolders shows one <Empty folder> item, which returns Null if selected.
- Copy the whole module, including its Selector details submodule; its objects refer to one another by name.
- A module copied on its own still refers to
Maximum_items. Add the library too, create your ownMaximum_items, or replace the reference with a fixed number.
Functions
| Function | What it does |
|---|---|
File_menu_paths(folder, max_items) |
Returns the relative path of every visible file beneath «folder», searching one folder at a time. Returns a one-item message list when the folder is blank, the limit is invalid or exceeded, or no files are found. |
Folder_menu_paths(folder, max_items) |
Returns . plus the relative path of every visible descendant folder. Files are ignored.
|
File_selector_paths(folder, max_items) |
As File_menu_paths, plus an <Empty folder> entry for each empty folder. Used by the reusable file selector.
|
Folder_selector_paths(folder, max_items) |
Same logic as Folder_menu_paths. Used by the reusable folder selector.
|
File_menu_nesting(relative_path) |
Converts a path's folder part to the >-separated form «nestUnder» expects, for example Finance\2025\report.csv → Finance>2025. Returns Null for top-level items. File_selector_nesting and Folder_selector_nesting are identical copies.
|
«max_items» defaults to 50 when omitted; the library passes Maximum items. To build a menu of your own from these functions:
Choice(
Available_files, 1, inclAll: False,
labels: FilePathPart(Available_files, 'filename'),
selectionLabels: Available_files,
nestUnder: File_menu_nesting(Available_files)
)
Menu messages
When there is nothing to select, a menu shows one message, and the matching full-path variable returns Null.
| Message | Meaning |
|---|---|
| <Enter a starting folder> | The starting folder is blank. |
| <Enter a positive whole-number item limit> | Maximum items is less than 1 or not a whole number. |
| <Item limit exceeded - increase limit or choose a narrower folder> | The file scan found more files and folders than Maximum items. |
| <Folder limit exceeded - increase limit or choose a narrower folder> | The folder scan found more folders than Maximum items. |
| <No files found> | There are no visible files beneath the starting folder. |
| <Empty folder> | Reusable file selector only: the folder has no files and no subfolders. |
Tips
- Reference the full-path variables, not the relative selections, and guard against Null:
If IsNull(Selected_full_path) Then 'No file selected' Else ReadTextFile(Selected_full_path)
- If a file appears in the wrong submenu, open File menu debugging in the File menu details module. It shows each path's menu label, «nestUnder» value and full menu hierarchy.
- Keep the starting folder as narrow as practical; it keeps menus short and scans fast.
- The library does not check that the starting folder exists. If a menu shows <No files found> unexpectedly, check the path for typos.