If I got it right something like this should work actually.
First you get all desired files from the directory you specify sorted by their file names:
$FileList =
Get-ChildItem -Path 'D:\sample' -Filter 'testfile*.mp3' |
Sort-Object -Property BaseName
The result would be something similar to this:
$FileList =
'testfile001_TR1',
'testfile001_TR2',
'testfile001_TR3',
'testfile002_TR1',
'testfile002_TR2',
'testfile002_TR3',
'testfile256_TR1',
'testfile256_TR2',
'testfile256_TR3'
Now you can use a for loop to process the files in chunks of 3 as you like:
for ($i = 0; $i -lt $FileList.Count; $i += 3) {
"Chunk Number '$(($i/3) + 1 )'"
"Do something meaningful with the file #1 '$($FileList[$i])'"
"Do something meaningful with the file #2 '$($FileList[$i + 1])'"
"Do something meaningful with the file #3 '$($FileList[$i + 2])'"
}
The sample output would look like this:
Chunk Number '1'
Do something meaningful with the file #1 'testfile001_TR1'
Do something meaningful with the file #2 'testfile001_TR2'
Do something meaningful with the file #3 'testfile001_TR3'
Chunk Number '2'
Do something meaningful with the file #1 'testfile002_TR1'
Do something meaningful with the file #2 'testfile002_TR2'
Do something meaningful with the file #3 'testfile002_TR3'
Chunk Number '3'
Do something meaningful with the file #1 'testfile256_TR1'
Do something meaningful with the file #2 'testfile256_TR2'
Do something meaningful with the file #3 'testfile256_TR3'