2

I want to prompt the user for a directory path.

The user can enter some text like C:\Pro in command line, tap tab button and the script should autocomplete the text toC:\Programs\ on another tab it should change the text to C:\Program Files\.

So, the script should scan folders and help user to navigate between them on typing.

Important: I can't use any GUI dialogs, because I am going to use the script on Win with no GUI.

This code will not work:

New-Object System.Windows.Forms.FolderBrowserDialog
mklement0
  • 382,024
  • 64
  • 607
  • 775
Hyper
  • 327
  • 1
  • 5
  • 11
  • 2
    Possible duplicate of [Auto Complete User Input PowerShell 2.0](http://stackoverflow.com/questions/17114701/auto-complete-user-input-powershell-2-0) – Nkosi Dec 14 '16 at 22:05

1 Answers1

0

Ummm... you don't have to? PS already does that by default?

function T
{ 
    param
    (
        [System.IO.FileInfo]
        $P
    )
    $P.FullName
}

T -P # Pressing <tab> at this stage will automatically show you the first file in your working directory. That happens even if the P was of type string.
cogumel0
  • 2,430
  • 5
  • 29
  • 45
  • Nothing would work in the context of `Read-Host` in the way that you want. `Read-Host` only processes the entries once you hit enter. There's no way around that as far as `Read-Host` is concerned. Then what you want to do is really look at `$Host.UI.RawUI` and look at using `ReadKey()`, that way you can filter on what the key pressed was and perform whatever code you want on that particular key press. – cogumel0 Dec 14 '16 at 22:40
  • (I'm not the OP). I _inferred_ from the OP's question that `Read-Host` must be used, so - assuming that's the case - your answer doesn't help. You may want to add your clarification _directly to your answer_. – mklement0 Dec 14 '16 at 23:03
  • 1
    This doesn't work in a prompt for a mandatory script parameter. – montonero Sep 05 '19 at 07:51