Search code examples
powershelladministrator

Powershell: Test path by only knowing one part of the actual filename


Test-Path C:\Temptest\keeran* -PathType Leaf

The command will give a true, coz I have got a file that begins with the name keeran.

How can I do the same, but I have put the path into a variable. How can I use the * The following command doesn't work

$ppath =  C:\Temptest
$file = keeran
## Doesn't work
Test-Path -Path "$ppath\$file*"

How should I do that?


Solution

  • I tested it on my computer and it worked, the only thing I did was adding the quotes. This code worked for me:

    $ppath =  "C:\Temptest"
    $file = "keeran"
    ## Doesn't work
    Test-Path -Path "$ppath\$file*"
    

    What error did you get?