Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Powershell not finding a pattern in a string

$
0
0

Using the code below, I am looking for a specified string in the file name and it will return the path and file name

Get-ChildItem “C:\temp2” -recurse | Select-String -pattern "R550707_R55070718" | group path | select name

however it is not finding the file

Here is my setup
In the folder c:\temp2 I have files
R550707_R55070701_1212.pdf
R550707_R55070702_1518.pdf
R550707_R55070703_4250.pdf
R550707_R55070704_3232.pdf
...
...
R550707_R55070717_3232.pdf
R550707_R55070718_1222.pdf
R550707_R55070719_1202.pdf
R550707_R55070720_5502.pdf

Here are some of the strange results I'm getting
If I look for string "R550707_R55070701" the results return files R550707_R55070701_1212.pdf and R550707_R55070718_1222.pdf
So that is wrong. It should only return the first one. The second file doesn't even match the criteria string. If I search for more of the string (eg. "R550707_R55070701_12") it finds the single file but shouldn't need the extra charracters as it is unique enough.

If looking for "R550707_R55070718" it returns nothing.
If I search for any other similar string the code works perfect. (eg. "R550707_R55070704" returns R550707_R55070704_3232.pdf)

I have tried right click on the R550707_R55070718_1222.pdf file name and copied and pasted it directly into the code at the top and still not finding it.

I tried having the code use “C:\temp2\*.pdf” but no difference. I'm using windows 7 Powershell in command prompt mode and the gui version.

Any ideas on what I'm missing ?


Viewing all articles
Browse latest Browse all 15028

Trending Articles



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