This PowerShell command line:
code (Get-ChildItem $Home\.vscode\extensions\ms-vscode.PowerShell-*\examples)[-1]
is from the page here: https://code.visualstudio.com/docs/languages/powershell
It opens up the folder in question in VS Code.
What is the purpose of the index [-1]
after the GCI? I tried running the command without any index at all, and VS Code opened up in exact identical layout.
CodePudding user response:
As requested, my comment as answer:
Using array index [-1]
returns the last item of that array.
Because of the asteriks in the path (where the version number of the PowerShell extension is), an array of directories is expected.
Perhaps even better would be to use
@(Get-ChildItem $Home\.vscode\extensions\ms-vscode.PowerShell-*\examples)[-1]
where the @()
forces the result to be an array, even if only one directory is found.
For more array indexing possibilities, please follow the link in zett42's comment