Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Find files that match with given string, except one character in a fixed position

$
0
0
Hi,

I want to find files in a directory with a given string (ss-20140129-process-000*.sdx), where only one character will be mismatched, so have to use wildcard for that character. This means I am looking for filenames where everything needs to be matched except one character in position of "*". For the samples given below: 1st 3 files matched with the given string, but last 3 files have not matched, so first 3 files will be counted.


ss-20140129-process-0001.sdx
ss-20140129-process-0004.sdx
ss-20140129-process-0009.sdx
zx-20140129-process-0001.sdx
bt-20140129-process-0002.sdx
zx-20140129-process-0001.sdx


I can use the command like (GCI -path $folder -filter ss-20140129-process-000?.sdx), BUT problem is i am building a string for the filter (code given below), where i DO NOT know how to use "?" within the string to make a character exception.


Code:
$datevalue = [datetime]::parseexact($trandate,"MMddyy",$null)
$yyyymmdd = $datevalue.tostring('yyyyMMdd')

$FileToCheck = ("ss-"+$yyyymmdd+"-process-000?.sdx")

GCI -path $folder -filter $FileToCheck

But it's definitely NOT working for syntax problem.
Any help?





Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>