in my script I check some files and would like to replace a part of their full path with another string (unc path of the corresponding share).
Example:
$fullpath = "D:\mydir\myfile.txt"
$path = "D:\mydir"
$share = "\\myserver\myshare"
write-host ($fullpath -replace $path, $share)
The last line gives me an error since $path does not not contain a valid pattern for regular expressions.
How can I modify the line to make the replace operator handle the content of the variable $path as a literal?
Thanks in advance,
Kevin
Use
[regex]::Escape()– very handy methodYou might also use my filter
rebaseto do it, look at Powershell: subtract $pwd from $file.Fullname