← Back to Home • Next: File — Methods →
A lazy-loaded file-system tree where the user browses folders and picks one file or folder, confirming with Enter.
File renders the file system as an expandable/collapsible tree rooted at a folder you choose. It
loads each directory’s contents only when the folder is expanded (and releases them when collapsed),
so memory stays proportional to what is on screen — not to the size of the drive. You can filter
files by pattern, list folders only, restrict selection to files, show or hide hidden/system
entries, and pre-select a path.
☑️ Need to pick several files or folders at once? Use the MultiFile control — same tree browser, with checkboxes.
| Sub-page | What you will find |
|---|---|
| Index (this page) | What it is, when to use it, first examples, the method map |
| Methods | Every fluent method — signature, parameters, defaults, and a snippet |
| Operations | Keyboard, tree navigation, filtering, selection rules, history |
| Styles | The FileStyles regions and how to recolor them |
Use File when… |
Consider instead… |
|---|---|
| The user picks one file or folder from disk | — |
| The user may pick several files/folders | MultiFile |
| The data is an arbitrary hierarchy (not the file system) | TreeSelect |
| The choice is from an in-memory list | Select |
| The data is tabular (multiple columns) | TableSelect |
using PromptPlusLibrary;
var result = PromptPlus.Controls
.File("Select a file or folder")
.Root(@"C:\Projects")
.Run();
if (!result.IsAborted)
PromptPlus.Console.WriteLine($"You chose {result.Content?.FullPath}");
File("Select a file or folder") creates the browser; the argument is the prompt text..Root(...) sets the folder the tree starts at. Without it, the current directory is used..Run() renders the tree and blocks until Enter (confirm) or Esc (abort), returning a
ResultPrompt<FileItem?>.Run() returns ResultPrompt<FileItem?>. FileItem is a small sealed class — not
System.IO.FileInfo — describing the chosen entry:
var result = PromptPlus.Controls.File("Pick a file").Root(root).Run();
if (!result.IsAborted && result.Content is not null)
{
var f = result.Content;
PromptPlus.Console.WriteLine(f.FullPath); // full path on disk
PromptPlus.Console.WriteLine(f.Name); // display name
PromptPlus.Console.WriteLine($"{f.IsDirectory}"); // folder or file?
PromptPlus.Console.WriteLine($"{f.Length} bytes");// 0 for directories
PromptPlus.Console.WriteLine($"{f.LastWriteTime}");
}
FileItem.ToString() returns FullPath, so the item prints as its path.
using PromptPlusLibrary;
var result = PromptPlus.Controls
.File("Select a C# file", "Right/+ expand, Left/- collapse, Enter to select")
.Root(@"C:\Projects")
.SearchPattern("*.cs") // only *.cs files are listed (folders always show)
.SelectFilesOnly() // folders can be expanded but not returned
.HideSize() // drop the size column
.PageSize(12) // 12 visible rows
.Run();
This combines a file filter, a selection rule, and paging — see Operations for how they behave together.
Grouped by purpose. Full signatures and examples are on the Methods page.
| Purpose | Methods |
|---|---|
| Choose the root | Root |
| Filter what is listed | SearchPattern, OnlyFolders, ShowHidden, ShowSystem |
| Selection rule | SelectFilesOnly |
| Layout & display | HideSize, ShowFullPath, PageSize |
| Initial value | Default |
| History | EnableHistory |
| Appearance & behavior | Styles, Options |
| Run | Run |
File returns ResultPrompt<FileItem?> — the single chosen entry.
| Member | Meaning |
|---|---|
.Content |
The selected FileItem (null if aborted) |
.IsAborted |
true when the user pressed Esc |
var (item, aborted) = PromptPlus.Controls.File("Pick").Root(root).Run();
if (!aborted) PromptPlus.Console.WriteLine(item?.FullPath);