Hello,
I’m having some trouble figuring out how to use open and closing parentheses in a search string.
I’m currently running a test to find any folder with “(59946)” in the name. I’ll be using a variable for the numbered portion, but all are enclosed in parentheses once I get the parentheses to work in the search.
I’ve tried a few online suggestions for escaping special characters in a double-quoted string to no avail. I understand the backtick (`) is the escape character, and others have suggested using the backslash (\). However, neither yield any results:
$folder = '59946'
$folder = (Get-ChildItem -Path $srcPath -Include "*`($folder`)*" -Recurse -Directory
$folder = (Get-ChildItem -Path $srcPath -Include "*\($folder\)*" -Recurse -Directory
$folder = (Get-ChildItem -Path $srcPath -Include "`*`($folder`)`*" -Recurse -Directory
Ultimately I’ll be running this in a foreach loop to build a simple array. Something like this:
$quizList = Get-Content "$dstPath\list_current_week.txt"
Foreach ($quiz in $quizList) {
$current_week = (Get-ChildItem -Path $srcPath -Include "`*`($quiz`)`*" -Recurse -Directory).Fullname
$current_week =+ $current_week
}
$current_week
I can get a basic search to work if I build out the variable several times, but this doesn’t seem like the most effective/professional way of performing this kind of search.
$folder = '59946'
$folder = "(" + $folder + ")"
$folder = (Get-ChildItem -Path $srcPath -Include *$folder* -Recurse -Directory).Fullname
Results:
Gateway Arch (Murray) (59946) - LG 3.1
Any help would be greatly appreciated…