← Back to Home • Next: File — Operations →
Every fluent method on IFileControl. Each returns the same control instance, so calls chain in any
order. Call Run last.
The factory is
PromptPlus.Controls.File(string prompt = "", string? description = null), which returnsIFileControl.
Quick jump: Root · SearchPattern · OnlyFolders · ShowHidden · ShowSystem · SelectFilesOnly · HideSize · ShowFullPath · PageSize · Default · EnableHistory · Styles · Options · Run
RootIFileControl Root(string path)
Sets the folder the tree starts at. When not set, the current directory
(Directory.GetCurrentDirectory()) is used. Point it at a drive root (e.g. C:\) to browse a whole
volume.
PromptPlus.Controls.File("Pick")
.Root(@"C:\Projects")
.Run();
Throws
ArgumentNullExceptionifpathisnull.
SearchPatternIFileControl SearchPattern(string pattern)
Filters files by a wildcard pattern; directories are always listed so the tree can be navigated.
Default is * (all files).
PromptPlus.Controls.File("Pick a C# file")
.Root(root)
.SearchPattern("*.cs")
.Run();
Throws
ArgumentNullExceptionifpatternisnull.
OnlyFoldersIFileControl OnlyFolders(bool value = true)
Lists directories only, hiding all files. Useful when the user should pick a folder.
PromptPlus.Controls.File("Pick a folder").Root(root).OnlyFolders().Run();
ShowHiddenIFileControl ShowHidden(bool value = true)
Includes entries marked with the Hidden attribute. Hidden by default.
ShowSystemIFileControl ShowSystem(bool value = true)
Includes entries marked with the System attribute. Hidden by default.
PromptPlus.Controls.File("Browse (incl. hidden/system)")
.Root(root)
.ShowHidden()
.ShowSystem()
.Run();
SelectFilesOnlyIFileControl SelectFilesOnly(bool value = true)
Restricts the returned entry to files. Folders can still be expanded and browsed, but pressing Enter on a folder does not confirm it.
PromptPlus.Controls.File("Pick a file")
.Root(root)
.SearchPattern("*.cs")
.SelectFilesOnly()
.Run();
HideSizeIFileControl HideSize(bool value = true)
Hides the file-size column shown next to files.
PromptPlus.Controls.File("Pick").Root(root).HideSize().Run();
ShowFullPathIFileControl ShowFullPath(bool value = true)
Sets whether the answer/summary shows the full path or just the entry name for the selected item. Default is to show only the name. The user can flip this at runtime with the full-path hotkey (Shift+F3) regardless of the initial value.
PromptPlus.Controls.File("Select (answer shows short name)")
.Root(root)
.ShowFullPath(false)
.Run();
PageSizeIFileControl PageSize(byte value)
Rows visible at once (valid range 0–255). 0 (default) auto-fits to the console height, reserving
lines for the header, footer, and pagination.
PromptPlus.Controls.File("Pick").Root(root).PageSize(12).Run();
DefaultIFileControl Default(string fullPath, bool useDefaultHistory = true)
Pre-selects a file or directory, expanding the tree down to it when the path lies under the root.
When useDefaultHistory is true and history is enabled, a stored value may
override this default.
PromptPlus.Controls.File("Pick")
.Root(root)
.Default(@"C:\Projects\App\Program.cs")
.Run();
Throws
ArgumentNullExceptioniffullPathisnull.
EnableHistoryIFileControl EnableHistory(string filename, Action<IHistoryOptions>? options = null)
Persists the confirmed path to filename and can restore it as the default on the next run (the tree
expands to it). The IHistoryOptions builder is identical to the one documented for
Input → EnableHistory (MinPrefixLength, MaxItems,
ExpirationTime, FilterType, PageSize).
PromptPlus.Controls.File("Pick a file (remembered)")
.Root(root)
.EnableHistory("file-history")
.Run();
Throws
ArgumentNullExceptioniffilenameisnull.
StylesIFileControl Styles(FileStyles styleType, Style style)
Recolors one visual region of this control. See the region list and examples on the Styles page.
using PromptPlusLibrary;
using ConsolePlusLibrary; // Color, Style live here
PromptPlus.Controls.File("Pick").Root(root)
.Styles(FileStyles.FileTypeFolder, new Style(Color.Cyan, Color.Default))
.Run();
OptionsIFileControl Options(Action<IControlOptions> options)
Overrides global behaviors for this one control (prompt/description text, abort key, tooltip, hide-after-finish). See Global Behaviors → Per-Control Override.
PromptPlus.Controls.File("Pick").Root(root)
.Options(opt =>
{
opt.ShowTooltip(true);
opt.EnabledAbortKey(true);
opt.HideAfterFinish(false);
})
.Run();
Throws
ArgumentNullExceptionifoptionsisnull.
RunResultPrompt<FileItem?> Run(CancellationToken token = default)
Renders the tree and blocks until the user confirms (Enter) or aborts (Esc). Returns
ResultPrompt<FileItem?>; .Content is null when aborted.
var result = PromptPlus.Controls.File("Pick").Root(root).Run();
if (!result.IsAborted)
PromptPlus.Console.WriteLine(result.Content?.FullPath);
FileStyles regions