mercredi 17 juin 2015

Get actual path from path with wildcard

When using Test-Path in an if statement, I am looking to get the path that the if statement succeeds with.

For example, these files exist in C:

C:\Test6_1_15.txt
C:\Test6_2_15.txt
C:\Test6_3_15.txt
C:\Test6_4_15.txt

what do I do in the "then" branch?

$Path = "C:\Test6_*_15.txt"
if (Test-Path $Path)
{
   # if test passes because there are 4 files that fit the test, but I want to be
   # able to output the file that made the if statement succeed. 
}

Aucun commentaire:

Enregistrer un commentaire