Read-ConsolePath
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>]#All Parameter SetsDescription
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 @pathOptionsAn 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 @textOptionsSelect an existing inventory directory
Example 3
Get-ConsoleDemo -Slug 'prompt-tour' | Select-Object -ExpandProperty SourceRead 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
- The folder relative paths start from (default: the current location).
- -Default String
- The path initially shown in the editor; pressing Enter accepts it.
- -Description String
- Help text under the question.
- -Extension String[]
- File extensions offered as suggestions (.csv, .json).
- -Kind PathKind
- What is accepted: Any, File or Folder.
- Possible values:
Any,File,Folder - -Mode InteractionMode
- 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
- Requires the path to exist.
- -ParameterName String
- The parameter of your script that supplies this value without a prompt (named in the non-interactive error, for example -Domain).
- Includes hidden files and folders in completion suggestions.
- -Suggestions Int32
- Maximum visible completion suggestions; default six.
- -Title String
- 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.