Wildcard that reads for variable repetition of a single integer

Hello all,

Is there a way I can set a variable as a repeating integer of variable repetitions?

As in, could I replace the wildcard in “DSC*0” with something that only reads for zeros?

Context:
I am using this script to copy a list of photos into a subfolder.

$E = "DSC*0"

Get-Content .\list.txt |
Foreach-Object { copy-item -Path "$E$_.jpg" -Destination ".\subfolder"}

This will copy the files in the list, but because of the way the variable is structured, it also copies any other photo with the last digits matching the number in the list.

ie: With range of photos DSC00001:DSC00301, the number ‘2’ in ‘list.txt’ will result in the following copies in the subfolder: DSC00002, DSC00102, DSC00202.

Whereas I want it to only copy the photo DSC00002.

I can circumvent the problem by adding zeros before the number in the list but there I think there must be a way to handle it in the script.

Hopefully that all makes sense. Let me know if I can make it clearer.

Thanks in advance.

Not exactly sure of your requirements, but something like this may help:

$regex = 'DSC0{4}2$'

$files = 'DSC00202','DSC00102','DSC00002'

$files | ForEach-Object {
    if($PSItem -match $regex){
        $PSItem
        #Copy-Item -Path $file -Destination ".\subfolder"
    }
}

The above solution of Wes will only work if you have 4 zero’s between DSC and 2. If you’re in need of more or less zero’s, you could use the following regex.

[pre] $regex = “DSC[0]+2$” [/pre]