The Muffin Man
The Muffin Man

Reputation: 20004

Getting resolved file path in Powershell

I need to find a file that has a folder in its path that has a dynamic name that changes as I publish some app. (it has a version # appended to it).

C:\somefolder\application_1.0.5.0\myxmlfile.xml

$FilePath = "C:\somefolder\application*\myxmlfile.xml"

Which works great, but I'm changing xml and need to save it again. Upon saving it it's complaining about an illegal character in the path "*".

[xml] $xml = Get-Content..
$xml.Save($FilePath) 

How can I get the path that powershell actually resolved in $FilePath so that I can pass it to the xml save function?

Upvotes: 2

Views: 1049

Answers (2)

Greg Bray
Greg Bray

Reputation: 15707

the Resolve-Path cmdlet will convert wildcards to a full path. Alternatively you could use something like:

$filepattern = "C:\somefolder\application*\myxmlfile.xml"
$filepath = gci $filepattern  | select -First 1 -ExpandProperty FullName

Upvotes: 3

Zombo
Zombo

Reputation: 1

PS > $FilePath = 'C:\Window*\win.ini'

PS > Convert-Path $FilePath
C:\Windows\win.ini

Upvotes: 3

Related Questions