0

We have a library of 3500 documents for which we're building metadata. About 1/3 of the documents have BC in the title and I want to flag these. Right now, here's what I have and it works fine:

$htmPath = "c:\ht"
$srcfiles = Get-ChildItem $htmPath -filter "*.htm*"
ForEach ($doc in $srcfiles)
{
    $s = $doc.Fullname
    if($s.contains("BC")) { $bcflag = 1 } else {$bcflag = 0}
    Write-Host "File: " $doc.Fullname "  BC Flag: " $bcflag
}

It's just come to my attention that there may be some documents with bc in the title, so I need to add an OR to my condition test. I've been unsuccessful with the word OR...errors out with bad method calls, | as a symbol for or...thinks I'm trying to pipe something, and for some reason, I can't include a regex. I can get it to work if I add a duplicate if statement with bc as a condition, but there has to be a way to provide a list of options rather than a series of statements each looking for a single value.

What is the proper syntax to

a.) Provide a list of conditions to test and/or

b.) use a regex in the above statement

2 Answers 2

1

The or operator in Powershell is -or so you probably want

if($s.contains("BC") -or $s.contains("bc")) { $bcflag = 1 } else {$bcflag = 0}
Sign up to request clarification or add additional context in comments.

Comments

1

using regex:

if($s -match 'bc')

or just

if($doc.fullname -match 'bc')

default regex isn't case-sensitive, the will match "BC" or "bc".

Comments

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.