Skip to content
ConsoleMonster
Cmdlet

Read-ConsolePath

Module
ConsoleMonster
Outputs
System.String

Asks for a file or folder path, with completion.

Syntax

Read-ConsolePath
[-BasePath <String>]
[-Default <String>]
[-Description <String>]
[-Extension <String[]>]
[-Kind <Any|File|Folder>]
[-Mode <Rich|Line|Accessible|Snapshot>]
[-MustExist]
[-ParameterName <String>]
[-ShowHidden]
[-Suggestions <Int32>]
[[-Title] <String>]
[<CommonParameters>]
#
Parameter set: All Parameter Sets

Description

Matching entries of the typed folder are listed under the box (folders first); Tab completes the common part or the focused entry, Up and Down move through them. -Kind File or Folder and -MustExist are checked on Enter. Returns the path as typed (environment variables and ~ are expanded only when checking).

Examples

Example 1

$pathOptions = @{
    MustExist = $true
    Title = 'Import file'
    Kind = 'File'
    Extension = @('.csv')
}
$file = Read-ConsolePath @pathOptions

An existing CSV file

Example 2

$pathOptions = @{
    MustExist = $true
    Title = 'Inventory folder'
    Default = '.'
    Kind = 'Folder'
}
$path = Read-ConsolePath @pathOptions
$textOptions = @{
    Text = @("Inventory folder: $path")
}
Write-ConsoleText @textOptions

Select an existing inventory directory

Example 3

Get-ConsoleDemo -Slug 'prompt-tour' | Select-Object -ExpandProperty Source

Read the gallery script to see Read-ConsolePath in a complete example. Each lookup returns the script's source. Use the same slug with Show-ConsoleDemo to run it.

Parameters

-BasePath String optional
The folder relative paths start from (default: the current location).
-Default String optional
The path initially shown in the editor; pressing Enter accepts it.
-Description String optional
Help text under the question.
-Extension String[] optional
File extensions offered as suggestions (.csv, .json).
-Kind PathKind optional
What is accepted: Any, File or Folder.
Possible values: Any, File, Folder
-Mode InteractionMode optional
Forces how to ask: Rich (in-place prompt), Line (question and typed answer), Accessible (numbered, no redraws) or None (use the default or fail).
Possible values: Rich, Line, Accessible, Snapshot
-MustExist SwitchParameter optional
Requires the path to exist.
-ParameterName String optional
The parameter of your script that supplies this value without a prompt (named in the non-interactive error, for example -Domain).
-ShowHidden SwitchParameter optional
Includes hidden files and folders in completion suggestions.
-Suggestions Int32 optional
Maximum visible completion suggestions; default six.
-Title String optionalposition: 0
The prompt displayed above the input control.

Common Parameters

This command supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.

For more information, see about_CommonParameters.