2

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?

2 Answers 2

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

PS > Convert-Path $FilePath
C:\Windows\win.ini
Sign up to request clarification or add additional context in comments.

4 Comments

Interesting. The help for convert-path says that wildcards aren't allowed.
@MikeShepard That is if you use the LiteralPath argument. This is implicily using the Path argument.
@MikeShepard yeah but it says that here too technet.microsoft.com/en-us/library/hh849858
So the documentation is wrong in more than one place?
3

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

1 Comment

Alias for Get-ChildItem. It is the PS equivalent of DIR or LS

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.